effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_1 a b = disjoint a b
let disjoint_1 a b =
false
null
false
disjoint a b
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Buffer.disjoint" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_1 : a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> Type0
[]
FStar.Buffer.disjoint_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> Type0
{ "end_col": 33, "end_line": 199, "start_col": 21, "start_line": 199 }
FStar.Pervasives.Lemma
val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j)
val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h =
false
null
true
let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j: nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j: nat). j < v len ==> get h b2 j == Seq.index s2 j)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "Prims.eqtype", "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "Prims.cut", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Prims.eq2", "FStar.Buffer.get", "FStar.Seq.Base.index", "Prims.unit", "FStar.Seq.Base.seq", "FStar.Seq.Base.length", "FStar.Buffer.sub", "FStar.UInt32.uint_to_t", "FStar.Buffer.as_seq", "FStar.UInt32.__uint_to_t" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
[]
FStar.Buffer.eq_lemma2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b1: FStar.Buffer.buffer a -> b2: FStar.Buffer.buffer a -> len: FStar.UInt32.t { FStar.UInt32.v len <= FStar.Buffer.length b1 /\ FStar.UInt32.v len <= FStar.Buffer.length b2 } -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len)) (ensures forall (j: Prims.nat). j < FStar.UInt32.v len ==> FStar.Buffer.get h b1 j == FStar.Buffer.get h b2 j) [SMTPat (FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))]
{ "end_col": 66, "end_line": 1112, "start_col": 30, "start_line": 1108 }
FStar.HyperStack.ST.ST
val rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b
val rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) let rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) =
true
null
false
let h0 = HST.get () in let s = Seq.create (v len) init in let content:reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get () in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.UInt32.t", "Prims.bool", "Prims.unit", "FStar.Buffer.lemma_upd", "FStar.Buffer.lseq", "FStar.UInt32.v", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Buffer.as_seq", "FStar.Buffer.sel", "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Buffer._buffer", "FStar.Buffer.MkBuffer", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.reference", "FStar.HyperStack.ST.ralloc_mm", "FStar.Heap.trivial_preorder", "FStar.HyperStack.ST.mmmref", "FStar.HyperStack.ST.ralloc", "FStar.HyperStack.ST.mref", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "FStar.HyperStack.ST.is_eternal_region", "Prims.l_and", "FStar.Buffer.rcreate_post_common", "Prims.eq2", "FStar.Monotonic.HyperStack.is_mm", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Buffer.__proj__MkBuffer__item__content" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rcreate_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (mm: bool) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm))
[]
FStar.Buffer.rcreate_common
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t -> mm: Prims.bool -> FStar.HyperStack.ST.ST (FStar.Buffer.buffer a)
{ "end_col": 5, "end_line": 889, "start_col": 3, "start_line": 880 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
let disjoint_2 a b b' =
false
null
false
disjoint a b /\ disjoint a b'
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "Prims.l_and", "FStar.Buffer.disjoint", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_2 : a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> Prims.logical
[]
FStar.Buffer.disjoint_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> Prims.logical
{ "end_col": 53, "end_line": 200, "start_col": 24, "start_line": 200 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
let disjoint_3 a b b' b'' =
false
null
false
disjoint a b /\ disjoint a b' /\ disjoint a b''
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "Prims.l_and", "FStar.Buffer.disjoint", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_3 : a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> Prims.logical
[]
FStar.Buffer.disjoint_3
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> Prims.logical
{ "end_col": 75, "end_line": 201, "start_col": 28, "start_line": 201 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
let disjoint_5 a b b' b'' b''' b'''' =
false
null
false
disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "Prims.l_and", "FStar.Buffer.disjoint", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b''
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_5 : a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> b''': FStar.Buffer.buffer _ -> b'''': FStar.Buffer.buffer _ -> Prims.logical
[]
FStar.Buffer.disjoint_5
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> b''': FStar.Buffer.buffer _ -> b'''': FStar.Buffer.buffer _ -> Prims.logical
{ "end_col": 125, "end_line": 203, "start_col": 39, "start_line": 203 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
let disjoint_4 a b b' b'' b''' =
false
null
false
disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b'''
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "Prims.l_and", "FStar.Buffer.disjoint", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b'
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_4 : a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> b''': FStar.Buffer.buffer _ -> Prims.logical
[]
FStar.Buffer.disjoint_4
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> b: FStar.Buffer.buffer _ -> b': FStar.Buffer.buffer _ -> b'': FStar.Buffer.buffer _ -> b''': FStar.Buffer.buffer _ -> Prims.logical
{ "end_col": 99, "end_line": 202, "start_col": 33, "start_line": 202 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
let disjoint_ref_1 (#t #u: Type) (a: buffer t) (r: reference u) =
false
null
false
frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.HyperStack.ST.reference", "Prims.l_or", "Prims.l_not", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Buffer.frameOf", "FStar.Monotonic.HyperStack.frameOf", "FStar.Heap.trivial_preorder", "Prims.pos", "FStar.Buffer.as_addr", "FStar.Monotonic.HyperStack.as_addr", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b''''
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_ref_1 : a: FStar.Buffer.buffer t -> r: FStar.HyperStack.ST.reference u169 -> Prims.logical
[]
FStar.Buffer.disjoint_ref_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer t -> r: FStar.HyperStack.ST.reference u169 -> Prims.logical
{ "end_col": 58, "end_line": 206, "start_col": 2, "start_line": 206 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
let disjoint_ref_2 a r r' =
false
null
false
disjoint_ref_1 a r /\ disjoint_ref_1 a r'
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.HyperStack.ST.reference", "Prims.l_and", "FStar.Buffer.disjoint_ref_1", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) =
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_ref_2 : a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> Prims.logical
[]
FStar.Buffer.disjoint_ref_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> Prims.logical
{ "end_col": 69, "end_line": 207, "start_col": 28, "start_line": 207 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
let disjoint_ref_4 a r r' r'' r''' =
false
null
false
disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r'''
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.HyperStack.ST.reference", "Prims.l_and", "FStar.Buffer.disjoint_ref_1", "FStar.Buffer.disjoint_ref_3", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r'
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_ref_4 : a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> r'': FStar.HyperStack.ST.reference _ -> r''': FStar.HyperStack.ST.reference _ -> Prims.logical
[]
FStar.Buffer.disjoint_ref_4
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> r'': FStar.HyperStack.ST.reference _ -> r''': FStar.HyperStack.ST.reference _ -> Prims.logical
{ "end_col": 87, "end_line": 209, "start_col": 37, "start_line": 209 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
let disjoint_ref_5 a r r' r'' r''' r'''' =
false
null
false
disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r''''
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.HyperStack.ST.reference", "Prims.l_and", "FStar.Buffer.disjoint_ref_1", "FStar.Buffer.disjoint_ref_4", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r''
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_ref_5 : a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> r'': FStar.HyperStack.ST.reference _ -> r''': FStar.HyperStack.ST.reference _ -> r'''': FStar.HyperStack.ST.reference _ -> Prims.logical
[]
FStar.Buffer.disjoint_ref_5
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.Buffer.buffer _ -> r: FStar.HyperStack.ST.reference _ -> r': FStar.HyperStack.ST.reference _ -> r'': FStar.HyperStack.ST.reference _ -> r''': FStar.HyperStack.ST.reference _ -> r'''': FStar.HyperStack.ST.reference _ -> Prims.logical
{ "end_col": 99, "end_line": 210, "start_col": 43, "start_line": 210 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
let modifies_none h h' =
false
null
false
HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h'
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem'", "FStar.Monotonic.HyperStack.is_wf_with_ctr_and_tip", "FStar.Monotonic.HyperStack.get_hmap", "FStar.Monotonic.HyperStack.get_rid_ctr", "FStar.Monotonic.HyperStack.get_tip", "Prims.l_and", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.modifies_transitively", "FStar.Set.empty", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_none : h: m: FStar.Monotonic.HyperStack.mem' { FStar.Monotonic.HyperStack.is_wf_with_ctr_and_tip (FStar.Monotonic.HyperStack.get_hmap m) (FStar.Monotonic.HyperStack.get_rid_ctr m) (FStar.Monotonic.HyperStack.get_tip m) } -> h': m: FStar.Monotonic.HyperStack.mem' { FStar.Monotonic.HyperStack.is_wf_with_ctr_and_tip (FStar.Monotonic.HyperStack.get_hmap m) (FStar.Monotonic.HyperStack.get_rid_ctr m) (FStar.Monotonic.HyperStack.get_tip m) } -> Prims.logical
[]
FStar.Buffer.modifies_none
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h: m: FStar.Monotonic.HyperStack.mem' { FStar.Monotonic.HyperStack.is_wf_with_ctr_and_tip (FStar.Monotonic.HyperStack.get_hmap m) (FStar.Monotonic.HyperStack.get_rid_ctr m) (FStar.Monotonic.HyperStack.get_tip m) } -> h': m: FStar.Monotonic.HyperStack.mem' { FStar.Monotonic.HyperStack.is_wf_with_ctr_and_tip (FStar.Monotonic.HyperStack.get_hmap m) (FStar.Monotonic.HyperStack.get_rid_ctr m) (FStar.Monotonic.HyperStack.get_tip m) } -> Prims.logical
{ "end_col": 74, "end_line": 237, "start_col": 2, "start_line": 237 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
let modifies_bufs rid buffs h h' =
false
null
false
modifies_ref rid (arefs buffs) h h' /\ (forall (#a: Type) (b: buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.TSet.set", "FStar.Buffer.abuffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_ref", "FStar.Buffer.arefs", "Prims.l_Forall", "FStar.Buffer.buffer", "Prims.l_imp", "Prims.eq2", "FStar.Buffer.frameOf", "FStar.Buffer.live", "FStar.Buffer.disjoint_from_bufs", "FStar.Buffer.equal", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_bufs : rid: FStar.Monotonic.HyperHeap.rid -> buffs: FStar.TSet.set FStar.Buffer.abuffer -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
FStar.Buffer.modifies_bufs
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
rid: FStar.Monotonic.HyperHeap.rid -> buffs: FStar.TSet.set FStar.Buffer.abuffer -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 130, "end_line": 234, "start_col": 2, "start_line": 233 }
Prims.GTot
val includes (#a: _) (x y: buffer a) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y
val includes (#a: _) (x y: buffer a) : GTot Type0 let includes #a (x: buffer a) (y: buffer a) : GTot Type0 =
false
null
false
x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "sometrivial" ]
[ "FStar.Buffer.buffer", "Prims.l_and", "Prims.eq2", "FStar.UInt32.t", "FStar.Buffer.__proj__MkBuffer__item__max_length", "Prims.op_Equals_Equals_Equals", "FStar.HyperStack.ST.reference", "FStar.Buffer.lseq", "FStar.UInt32.v", "FStar.Buffer.__proj__MkBuffer__item__content", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Buffer.idx", "Prims.op_Addition", "FStar.Buffer.length" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val includes (#a: _) (x y: buffer a) : GTot Type0
[]
FStar.Buffer.includes
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: FStar.Buffer.buffer a -> y: FStar.Buffer.buffer a -> Prims.GTot Type0
{ "end_col": 38, "end_line": 99, "start_col": 2, "start_line": 96 }
FStar.HyperStack.ST.Stack
val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let recall #a b = recall b.content
val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b =
true
null
false
recall b.content
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "Prims.l_and", "FStar.HyperStack.ST.is_eternal_region", "FStar.Buffer.frameOf", "Prims.b2t", "Prims.op_Negation", "FStar.Monotonic.HyperStack.is_mm", "FStar.Buffer.lseq", "FStar.UInt32.v", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.HyperStack.ST.recall", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b))
[]
FStar.Buffer.recall
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a { FStar.HyperStack.ST.is_eternal_region (FStar.Buffer.frameOf b) /\ Prims.op_Negation (FStar.Monotonic.HyperStack.is_mm (MkBuffer?.content b)) } -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 34, "end_line": 80, "start_col": 18, "start_line": 80 }
Prims.Tot
val modifies_0 (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
val modifies_0 (h0 h1: mem) : Type0 let modifies_0 (h0 h1: mem) : Type0 =
false
null
false
modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_one", "FStar.Monotonic.HyperStack.get_tip", "FStar.Buffer.modifies_buf_0", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_0 (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_0
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 35, "end_line": 385, "start_col": 2, "start_line": 383 }
Prims.Tot
val modifies_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
val modifies_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0 let modifies_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0 =
false
null
false
let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_one", "FStar.Buffer.modifies_buf_1", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.get_tip", "FStar.Buffer.frameOf" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 88, "end_line": 392, "start_col": 58, "start_line": 390 }
Prims.Tot
val modifies_2_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
val modifies_2_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0 let modifies_2_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0 =
false
null
false
HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.get_tip", "Prims.l_or", "FStar.Buffer.modifies_buf_1", "FStar.Monotonic.HyperStack.modifies_one", "Prims.l_not", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.union", "FStar.Set.singleton", "FStar.Buffer.modifies_buf_0", "FStar.Buffer.frameOf" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_2_1 (#a: Type) (b: buffer a) (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_2_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 80, "end_line": 399, "start_col": 2, "start_line": 395 }
FStar.HyperStack.ST.Stack
val assignL (#a: _) (l: list a) (b: buffer a) : Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec assignL #a (l: list a) (b: buffer a): Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) = lemma_seq_of_list_induction l; match l with | [] -> () | hd :: tl -> let b_hd = sub b 0ul 1ul in let b_tl = offset b 1ul in b_hd.(0ul) <- hd; assignL tl b_tl; let h = HST.get () in assert (get h b_hd 0 == hd); assert (as_seq h b_tl == Seq.seq_of_list tl); assert (Seq.equal (as_seq h b) (Seq.append (as_seq h b_hd) (as_seq h b_tl))); assert (Seq.equal (as_seq h b) (Seq.seq_of_list l))
val assignL (#a: _) (l: list a) (b: buffer a) : Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) let rec assignL #a (l: list a) (b: buffer a) : Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l)) =
true
null
false
lemma_seq_of_list_induction l; match l with | [] -> () | hd :: tl -> let b_hd = sub b 0ul 1ul in let b_tl = offset b 1ul in b_hd.(0ul) <- hd; assignL tl b_tl; let h = HST.get () in assert (get h b_hd 0 == hd); assert (as_seq h b_tl == Seq.seq_of_list tl); assert (Seq.equal (as_seq h b) (Seq.append (as_seq h b_hd) (as_seq h b_tl))); assert (Seq.equal (as_seq h b) (Seq.seq_of_list l))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "Prims.list", "FStar.Buffer.buffer", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Buffer.as_seq", "FStar.Seq.Properties.seq_of_list", "FStar.Seq.Base.append", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.List.Tot.Base.length", "FStar.Seq.Base.length", "FStar.Buffer.length", "FStar.Buffer.get", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Buffer.assignL", "FStar.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "FStar.Buffer.includes", "FStar.Buffer.offset", "Prims.l_and", "Prims.int", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.v", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "FStar.Buffer.sub", "FStar.Seq.Properties.lemma_seq_of_list_induction", "FStar.Buffer.live", "FStar.Buffer.modifies_1" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) (** Corresponds to memcmp for `eqtype` *) val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) let rec eqb #a b1 b2 len = if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false (** // Defining operators for buffer accesses as specified at // https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence // *) (* JP: if the [val] is not specified, there's an issue with these functions // * taking an extra unification parameter at extraction-time... *) val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let op_Array_Access #a b n = index #a b n val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let op_Array_Assignment #a b n z = upd #a b n z let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma (requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2)) (ensures (modifies_one (frameOf b) h0 h2)) [SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)] = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (** Corresponds to memcpy *) val blit: #t:Type -> a:buffer t -> idx_a:UInt32.t{v idx_a <= length a} -> b:buffer t{disjoint a b} -> idx_b:UInt32.t{v idx_b <= length b} -> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b} -> Stack unit (requires (fun h -> live h a /\ live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) == Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len) /\ Seq.slice (as_seq h1 b) 0 (v idx_b) == Seq.slice (as_seq h0 b) 0 (v idx_b) /\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) == Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) )) let rec blit #t a idx_a b idx_b len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in blit #t a idx_a b idx_b len'; let z = a.(idx_a +^ len') in b.(idx_b +^ len') <- z; let h1 = HST.get() in Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len'); Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b)); Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b)) end (** Corresponds to memset *) val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) == Seq.slice (as_seq h0 b) (v len) (length b) )) let rec fill #t b z len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in fill #t b z len'; b.(len') <- z; let h = HST.get() in Seq.snoc_slice_index (as_seq h b) 0 (v len'); Seq.lemma_tail_slice (as_seq h b) (v len') (length b) end; let h1 = HST.get() in Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z) let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) = sub b 0ul i, offset b i let join #t (b:buffer t) (b':buffer t{b.max_length == b'.max_length /\ b.content === b'.content /\ idx b + length b == idx b'}) : Tot (buffer t) = MkBuffer (b.max_length) (b.content) (b.idx) (FStar.UInt32.(b.length +^ b'.length)) val no_upd_lemma_0: #t:Type -> h0:mem -> h1:mem -> b:buffer t -> Lemma (requires (live h0 b /\ modifies_0 h0 h1)) (ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b)) [SMTPat (modifies_0 h0 h1); SMTPat (live h0 b)] let no_upd_lemma_0 #t h0 h1 b = () val no_upd_lemma_1: #t:Type -> #t':Type -> h0:mem -> h1:mem -> a:buffer t -> b:buffer t' -> Lemma (requires (live h0 b /\ disjoint a b /\ modifies_1 a h0 h1)) (ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b)) [SMTPat (modifies_1 a h0 h1); SMTPat (live h0 b)] let no_upd_lemma_1 #t #t' h0 h1 a b = () #reset-options "--z3rlimit 30 --initial_fuel 0 --max_fuel 0" val no_upd_lemma_2: #t:Type -> #t':Type -> #t'':Type -> h0:mem -> h1:mem -> a:buffer t -> a':buffer t' -> b:buffer t'' -> Lemma (requires (live h0 b /\ disjoint a b /\ disjoint a' b /\ modifies_2 a a' h0 h1)) (ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b)) [SMTPat (live h0 b); SMTPat (modifies_2 a a' h0 h1)] let no_upd_lemma_2 #t #t' #t'' h0 h1 a a' b = () val no_upd_lemma_2_1: #t:Type -> #t':Type -> h0:mem -> h1:mem -> a:buffer t -> b:buffer t' -> Lemma (requires (live h0 b /\ disjoint a b /\ modifies_2_1 a h0 h1)) (ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b)) [SMTPat (live h0 b); SMTPat (modifies_2_1 a h0 h1)] let no_upd_lemma_2_1 #t #t' h0 h1 a b = () val no_upd_fresh: #t:Type -> h0:mem -> h1:mem -> a:buffer t -> Lemma (requires (live h0 a /\ fresh_frame h0 h1)) (ensures (live h0 a /\ live h1 a /\ equal h0 a h1 a)) [SMTPat (live h0 a); SMTPat (fresh_frame h0 h1)] let no_upd_fresh #t h0 h1 a = () val no_upd_popped: #t:Type -> h0:mem -> h1:mem -> b:buffer t -> Lemma (requires (live h0 b /\ frameOf b =!= HS.get_tip h0 /\ popped h0 h1)) (ensures (live h0 b /\ live h1 b /\ equal h0 b h1 b)) [SMTPat (live h0 b); SMTPat (popped h0 h1)] let no_upd_popped #t h0 h1 b = () (* Modifies of subset lemmas *) let lemma_modifies_sub_0 h0 h1 : Lemma (requires (h1 == h0)) (ensures (modifies_0 h0 h1)) [SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_sub_1 #t h0 h1 (b:buffer t) : Lemma (requires (h1 == h0)) (ensures (modifies_1 b h0 h1)) [SMTPat (live h0 b); SMTPat (modifies_1 b h0 h1)] = () let lemma_modifies_sub_2 #t #t' h0 h1 (b:buffer t) (b':buffer t') : Lemma (requires (h1 == h0)) (ensures (modifies_2 b b' h0 h1)) [SMTPat (live h0 b); SMTPat (live h0 b'); SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_sub_2_1 #t h0 h1 (b:buffer t) : Lemma (requires (modifies_0 h0 h1 /\ live h0 b)) (ensures (modifies_2_1 b h0 h1)) [SMTPat (live h0 b); SMTPat (modifies_2_1 b h0 h1)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let modifies_subbuffer_1 (#t:Type) h0 h1 (sub:buffer t) (a:buffer t) : Lemma (requires (live h0 a /\ modifies_1 sub h0 h1 /\ includes a sub)) (ensures (modifies_1 a h0 h1 /\ live h1 a)) [SMTPat (modifies_1 sub h0 h1); SMTPat (includes a sub)] = () let modifies_subbuffer_2 (#t:Type) (#t':Type) h0 h1 (sub:buffer t) (a':buffer t') (a:buffer t) : Lemma (requires (live h0 a /\ live h0 a' /\ includes a sub /\ modifies_2 sub a' h0 h1 )) (ensures (modifies_2 a a' h0 h1 /\ modifies_2 a' a h0 h1 /\ live h1 a)) [SMTPat (modifies_2 sub a' h0 h1); SMTPat (includes a sub)] = () let modifies_subbuffer_2' (#t:Type) (#t':Type) h0 h1 (sub:buffer t) (a':buffer t') (a:buffer t) : Lemma (requires (live h0 a /\ live h0 a' /\ includes a sub /\ modifies_2 a' sub h0 h1 )) (ensures (modifies_2 a a' h0 h1 /\ live h1 a)) [SMTPat (modifies_2 a' sub h0 h1); SMTPat (includes a sub)] = () let modifies_subbuffer_2_1 (#t:Type) h0 h1 (sub:buffer t) (a:buffer t) : Lemma (requires (live h0 a /\ includes a sub /\ modifies_2_1 sub h0 h1)) (ensures (modifies_2_1 a h0 h1 /\ live h1 a)) [SMTPat (modifies_2_1 sub h0 h1); SMTPat (includes a sub)] = () let modifies_subbuffer_2_prime (#t:Type) h0 h1 (sub1:buffer t) (sub2:buffer t) (a:buffer t) : Lemma (requires (live h0 a /\ includes a sub1 /\ includes a sub2 /\ modifies_2 sub1 sub2 h0 h1)) (ensures (modifies_1 a h0 h1 /\ live h1 a)) [SMTPat (modifies_2 sub1 sub2 h0 h1); SMTPat (includes a sub1); SMTPat (includes a sub2)] = () let modifies_popped_3_2 (#t:Type) #t' (a:buffer t) (b:buffer t') h0 h1 h2 h3 : Lemma (requires (live h0 a /\ live h0 b /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_3_2 a b h1 h2)) (ensures (modifies_2 a b h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_3_2 a b h1 h2)] = () let modifies_popped_2 (#t:Type) #t' (a:buffer t) (b:buffer t') h0 h1 h2 h3 : Lemma (requires (live h0 a /\ live h0 b /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_2 a b h1 h2)) (ensures (modifies_2 a b h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_2 a b h1 h2)] = () let modifies_popped_1 (#t:Type) (a:buffer t) h0 h1 h2 h3 : Lemma (requires (live h0 a /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_2_1 a h1 h2)) (ensures (modifies_1 a h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_2_1 a h1 h2)] = () let modifies_popped_1' (#t:Type) (a:buffer t) h0 h1 h2 h3 : Lemma (requires (live h0 a /\ fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_1 a h1 h2)) (ensures (modifies_1 a h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_1 a h1 h2)] = () let modifies_popped_0 h0 h1 h2 h3 : Lemma (requires (fresh_frame h0 h1 /\ popped h2 h3 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3); SMTPat (modifies_0 h1 h2)] = () let live_popped (#t:Type) (b:buffer t) h0 h1 : Lemma (requires (popped h0 h1 /\ live h0 b /\ frameOf b =!= HS.get_tip h0)) (ensures (live h1 b)) [SMTPat (popped h0 h1); SMTPat (live h0 b)] = () let live_fresh (#t:Type) (b:buffer t) h0 h1 : Lemma (requires (fresh_frame h0 h1 /\ live h0 b)) (ensures (live h1 b)) [SMTPat (fresh_frame h0 h1); SMTPat (live h0 b)] = () let modifies_0_to_2_1_lemma (#t:Type) h0 h1 (b:buffer t) : Lemma (requires (modifies_0 h0 h1 /\ live h0 b)) (ensures (modifies_2_1 b h0 h1)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (live h0 b) ] = () let lemma_modifies_none_push_pop h0 h1 h2 : Lemma (requires (fresh_frame h0 h1 /\ popped h1 h2)) (ensures (modifies_none h0 h2)) = () let lemma_modifies_0_push_pop h0 h1 h2 h3 : Lemma (requires (fresh_frame h0 h1 /\ modifies_0 h1 h2 /\ popped h2 h3)) (ensures (modifies_none h0 h3)) = () let modifies_1_to_2_1_lemma (#t:Type) h0 h1 (b:buffer t) : Lemma (requires (modifies_1 b h0 h1 /\ live h0 b)) (ensures (modifies_2_1 b h0 h1)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (live h0 b) ] = () (* let modifies_1_to_2_lemma (#t:Type) #t' h0 h1 (b:buffer t) (b':buffer t'): Lemma *) (* (requires (modifies_1 b h0 h1 /\ live h0 b)) *) (* (ensures (modifies_2 b b' h0 h1)) *) (* [SMTPat (modifies_2 b b' h0 h1); SMTPat (live h0 b) ] *) (* = () *) let modifies_poppable_0 (h0 h1:mem) : Lemma (requires (modifies_0 h0 h1 /\ HS.poppable h0)) (ensures (HS.poppable h1)) [SMTPat (modifies_0 h0 h1)] = () let modifies_poppable_1 #t (h0 h1:mem) (b:buffer t) : Lemma (requires (modifies_1 b h0 h1 /\ HS.poppable h0)) (ensures (HS.poppable h1)) [SMTPat (modifies_1 b h0 h1)] = () let modifies_poppable_2_1 #t (h0 h1:mem) (b:buffer t) : Lemma (requires (modifies_2_1 b h0 h1 /\ HS.poppable h0)) (ensures (HS.poppable h1)) [SMTPat (modifies_2_1 b h0 h1)] = () let modifies_poppable_2 #t #t' (h0 h1:mem) (b:buffer t) (b':buffer t') : Lemma (requires (modifies_2 b b' h0 h1 /\ HS.poppable h0)) (ensures (HS.poppable h1)) [SMTPat (modifies_2 b' b h0 h1)] = () let modifies_poppable_3_2 #t #t' (h0 h1:mem) (b:buffer t) (b':buffer t') : Lemma (requires (modifies_3_2 b b' h0 h1 /\ HS.poppable h0)) (ensures (HS.poppable h1)) [SMTPat (modifies_3_2 b' b h0 h1)] = () let lemma_fresh_poppable (h0 h1:mem) : Lemma (requires (fresh_frame h0 h1)) (ensures (poppable h1)) [SMTPat (fresh_frame h0 h1)] = () let lemma_equal_domains_popped (h0 h1 h2 h3:mem) : Lemma (requires (equal_domains h0 h1 /\ popped h0 h2 /\ popped h1 h3)) (ensures (equal_domains h2 h3)) = () let lemma_equal_domains (h0 h1 h2 h3:mem) : Lemma (requires (fresh_frame h0 h1 /\ equal_domains h1 h2 /\ popped h2 h3)) (ensures (equal_domains h0 h3)) [SMTPat (fresh_frame h0 h1); SMTPat (equal_domains h1 h2); SMTPat (popped h2 h3)] = () let lemma_equal_domains_2 (h0 h1 h2 h3 h4:mem) : Lemma (requires (fresh_frame h0 h1 /\ modifies_0 h1 h2 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h2) /\ equal_domains h2 h3 /\ popped h3 h4)) (ensures (equal_domains h0 h4)) [SMTPat (fresh_frame h0 h1); SMTPat (modifies_0 h1 h2); SMTPat (popped h3 h4)] = () #reset-options "--z3rlimit 50" let rec assignL #a (l: list a) (b: buffer a): Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val assignL (#a: _) (l: list a) (b: buffer a) : Stack unit (requires (fun h0 -> live h0 b /\ length b = List.Tot.length l)) (ensures (fun h0 _ h1 -> live h1 b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.seq_of_list l))
[ "recursion" ]
FStar.Buffer.assignL
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
l: Prims.list a -> b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 57, "end_line": 1464, "start_col": 2, "start_line": 1452 }
Prims.Tot
val modifies_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )))
val modifies_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0 let modifies_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0 =
false
null
false
HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1)))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.get_tip", "Prims.l_or", "FStar.Buffer.modifies_buf_2", "FStar.Monotonic.HyperStack.modifies_one", "Prims.l_not", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.union", "FStar.Set.singleton", "FStar.Buffer.modifies_buf_1", "FStar.Buffer.frameOf" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 )))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> b': FStar.Buffer.buffer a' -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 72, "end_line": 406, "start_col": 2, "start_line": 402 }
Prims.Tot
val modifies_region (rid: rid) (bufs: TSet.set abuffer) (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
val modifies_region (rid: rid) (bufs: TSet.set abuffer) (h0 h1: mem) : Type0 let modifies_region (rid: rid) (bufs: TSet.set abuffer) (h0 h1: mem) : Type0 =
false
null
false
modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.TSet.set", "FStar.Buffer.abuffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_one", "FStar.Buffer.modifies_bufs", "Prims.eq2", "FStar.Monotonic.HyperStack.get_tip" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_region (rid: rid) (bufs: TSet.set abuffer) (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_region
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
rid: FStar.Monotonic.HyperHeap.rid -> bufs: FStar.TSet.set FStar.Buffer.abuffer -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 90, "end_line": 437, "start_col": 2, "start_line": 437 }
Prims.Tot
val modifies_3_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
val modifies_3_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0 let modifies_3_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0 =
false
null
false
HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.get_tip", "Prims.l_or", "FStar.Buffer.modifies_buf_2", "FStar.Monotonic.HyperStack.modifies_one", "Prims.l_not", "FStar.Buffer.modifies_buf_0", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.union", "FStar.Set.singleton", "FStar.Buffer.modifies_buf_1", "FStar.Buffer.frameOf" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_3_2 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1: mem) : Type0
[]
FStar.Buffer.modifies_3_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> b': FStar.Buffer.buffer a' -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 111, "end_line": 434, "start_col": 2, "start_line": 423 }
FStar.Pervasives.Lemma
val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty)
val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s =
false
null
true
Set.lemma_equal_intro (arefs s) (Set.empty)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.TSet.set", "FStar.Buffer.abuffer", "FStar.Set.lemma_equal_intro", "Prims.nat", "FStar.Buffer.arefs", "FStar.Set.empty", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)]
[]
FStar.Buffer.lemma_arefs_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s: FStar.TSet.set FStar.Buffer.abuffer -> FStar.Pervasives.Lemma (requires s == FStar.TSet.empty) (ensures FStar.Buffer.arefs s == FStar.Set.empty) [SMTPat (FStar.Buffer.arefs s)]
{ "end_col": 65, "end_line": 172, "start_col": 22, "start_line": 172 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set)
let disjoint_from_refs #a (b: buffer a) (set: Set.set nat) =
false
null
false
~(Set.mem (as_addr b) set)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.Set.set", "Prims.nat", "Prims.l_not", "Prims.b2t", "FStar.Set.mem", "FStar.Buffer.as_addr", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val disjoint_from_refs : b: FStar.Buffer.buffer a -> set: FStar.Set.set Prims.nat -> Prims.logical
[]
FStar.Buffer.disjoint_from_refs
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> set: FStar.Set.set Prims.nat -> Prims.logical
{ "end_col": 28, "end_line": 195, "start_col": 2, "start_line": 195 }
FStar.Pervasives.Lemma
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 =
false
null
true
Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.TSet.set", "FStar.Buffer.abuffer", "FStar.Set.lemma_equal_intro", "Prims.nat", "FStar.Buffer.arefs", "FStar.Buffer.op_Plus_Plus", "FStar.Set.union", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]]
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]]
[]
FStar.Buffer.lemma_arefs_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s1: FStar.TSet.set FStar.Buffer.abuffer -> s2: FStar.TSet.set FStar.Buffer.abuffer -> FStar.Pervasives.Lemma (ensures FStar.Buffer.arefs (s1 ++ s2) == FStar.Set.union (FStar.Buffer.arefs s1) (FStar.Buffer.arefs s2)) [ SMTPatOr [ [SMTPat (FStar.Buffer.arefs (s2 ++ s1))]; [SMTPat (FStar.Buffer.arefs (s1 ++ s2))] ] ]
{ "end_col": 76, "end_line": 182, "start_col": 2, "start_line": 182 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_0 rid h h' =
false
null
false
modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt: Type) (bb: buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_ref", "FStar.Set.empty", "Prims.nat", "Prims.l_Forall", "FStar.Buffer.buffer", "Prims.l_imp", "Prims.eq2", "FStar.Buffer.frameOf", "FStar.Buffer.live", "FStar.Buffer.equal", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_buf_0 : rid: FStar.Monotonic.HyperHeap.rid -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
FStar.Buffer.modifies_buf_0
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
rid: FStar.Monotonic.HyperHeap.rid -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 108, "end_line": 242, "start_col": 2, "start_line": 241 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
let modifies_buf_1 (#t: Type) rid (b: buffer t) h h' =
false
null
false
modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt: Type) (bb: buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Monotonic.HyperStack.modifies_ref", "FStar.Set.singleton", "Prims.nat", "FStar.Monotonic.Heap.addr_of", "FStar.Buffer.lseq", "FStar.Buffer.max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.as_ref", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "FStar.Buffer.frameOf", "FStar.Buffer.live", "FStar.Buffer.disjoint", "FStar.Buffer.equal", "Prims.logical" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modifies_buf_1 : rid: FStar.Monotonic.HyperHeap.rid -> b: FStar.Buffer.buffer t -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
[]
FStar.Buffer.modifies_buf_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
rid: FStar.Monotonic.HyperHeap.rid -> b: FStar.Buffer.buffer t -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> Prims.logical
{ "end_col": 125, "end_line": 246, "start_col": 2, "start_line": 245 }
Prims.Tot
val to_set_3 (n1 n2 n3: nat) : Set.set nat
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
val to_set_3 (n1 n2 n3: nat) : Set.set nat let to_set_3 (n1 n2 n3: nat) : Set.set nat =
false
null
false
Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Set.union", "FStar.Set.singleton", "FStar.Set.set" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val to_set_3 (n1 n2 n3: nat) : Set.set nat
[]
FStar.Buffer.to_set_3
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n1: Prims.nat -> n2: Prims.nat -> n3: Prims.nat -> FStar.Set.set Prims.nat
{ "end_col": 133, "end_line": 255, "start_col": 55, "start_line": 255 }
Prims.Tot
val to_set_4 (n1 n2 n3 n4: nat) : Set.set nat
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
val to_set_4 (n1 n2 n3 n4: nat) : Set.set nat let to_set_4 (n1 n2 n3 n4: nat) : Set.set nat =
false
null
false
Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Set.union", "FStar.Set.singleton", "FStar.Set.set" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val to_set_4 (n1 n2 n3 n4: nat) : Set.set nat
[]
FStar.Buffer.to_set_4
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n1: Prims.nat -> n2: Prims.nat -> n3: Prims.nat -> n4: Prims.nat -> FStar.Set.set Prims.nat
{ "end_col": 111, "end_line": 263, "start_col": 2, "start_line": 263 }
Prims.Tot
val to_set_2 (n1 n2: nat) : Set.set nat
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2)
val to_set_2 (n1 n2: nat) : Set.set nat let to_set_2 (n1 n2: nat) : Set.set nat =
false
null
false
Set.union (Set.singleton n1) (Set.singleton n2)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Set.union", "FStar.Set.singleton", "FStar.Set.set" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb)
false
true
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val to_set_2 (n1 n2: nat) : Set.set nat
[]
FStar.Buffer.to_set_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n1: Prims.nat -> n2: Prims.nat -> FStar.Set.set Prims.nat
{ "end_col": 93, "end_line": 248, "start_col": 46, "start_line": 248 }
Prims.GTot
val p (#a: Type0) (init: list a) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32)
val p (#a: Type0) (init: list a) : GTot Type0 let p (#a: Type0) (init: list a) : GTot Type0 =
false
null
false
normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "sometrivial" ]
[ "Prims.list", "Prims.l_and", "FStar.Pervasives.normalize", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.op_LessThanOrEqual", "FStar.UInt.max_int" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0"
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val p (#a: Type0) (init: list a) : GTot Type0
[]
FStar.Buffer.p
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
init: Prims.list a -> Prims.GTot Type0
{ "end_col": 59, "end_line": 828, "start_col": 2, "start_line": 827 }
Prims.GTot
val q (#a: Type0) (len: nat) (buf: buffer a) : GTot Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len)
val q (#a: Type0) (len: nat) (buf: buffer a) : GTot Type0 let q (#a: Type0) (len: nat) (buf: buffer a) : GTot Type0 =
false
null
false
normalize (length buf == len)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "sometrivial" ]
[ "Prims.nat", "FStar.Buffer.buffer", "FStar.Pervasives.normalize", "Prims.eq2", "FStar.Buffer.length" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val q (#a: Type0) (len: nat) (buf: buffer a) : GTot Type0
[]
FStar.Buffer.q
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
len: Prims.nat -> buf: FStar.Buffer.buffer a -> Prims.GTot Type0
{ "end_col": 31, "end_line": 831, "start_col": 2, "start_line": 831 }
FStar.Pervasives.Lemma
val lemma_modifies_1_1 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1 h2: _) : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else ()
val lemma_modifies_1_1 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1 h2: _) : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] let lemma_modifies_1_1 (#a: Type) (#a': Type) (b: buffer a) (b': buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] =
false
null
true
if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.op_Equality", "FStar.Monotonic.HyperHeap.rid", "FStar.Buffer.frameOf", "FStar.Buffer.modifies_trans_1_1'", "Prims.bool", "Prims.unit", "Prims.l_and", "FStar.Buffer.live", "FStar.Buffer.modifies_1", "Prims.squash", "FStar.Buffer.modifies_2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_modifies_1_1 (#a #a': Type) (b: buffer a) (b': buffer a') (h0 h1 h2: _) : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)]
[]
FStar.Buffer.lemma_modifies_1_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> b': FStar.Buffer.buffer a' -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b /\ FStar.Buffer.live h0 b' /\ FStar.Buffer.modifies_1 b h0 h1 /\ FStar.Buffer.modifies_1 b' h1 h2) (ensures FStar.Buffer.modifies_2 b b' h0 h2 /\ FStar.Buffer.modifies_2 b' b h0 h2) [SMTPat (FStar.Buffer.modifies_1 b h0 h1); SMTPat (FStar.Buffer.modifies_1 b' h1 h2)]
{ "end_col": 11, "end_line": 713, "start_col": 4, "start_line": 712 }
FStar.Pervasives.Lemma
val lemma_upd (#a: Type) (h: mem) (x: reference a {live_region h (HS.frameOf x)}) (v: a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m')
val lemma_upd (#a: Type) (h: mem) (x: reference a {live_region h (HS.frameOf x)}) (v: a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) let lemma_upd (#a: Type) (h: mem) (x: reference a {live_region h (HS.frameOf x)}) (v: a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) =
false
null
true
let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m')
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.reference", "Prims.b2t", "FStar.Monotonic.HyperStack.live_region", "FStar.Monotonic.HyperStack.frameOf", "FStar.Heap.trivial_preorder", "FStar.Set.lemma_equal_intro", "FStar.Monotonic.HyperHeap.rid", "FStar.Map.domain", "FStar.Monotonic.Heap.heap", "FStar.Map.t", "FStar.Map.upd", "FStar.Monotonic.Heap.upd", "FStar.Map.sel", "FStar.Monotonic.HyperStack.as_ref", "FStar.Monotonic.HyperHeap.hmap", "FStar.Monotonic.HyperStack.get_hmap", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Set.set", "FStar.Monotonic.HyperStack.upd", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_upd (#a: Type) (h: mem) (x: reference a {live_region h (HS.frameOf x)}) (v: a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v))))
[]
FStar.Buffer.lemma_upd
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h: FStar.Monotonic.HyperStack.mem -> x: FStar.HyperStack.ST.reference a {FStar.Monotonic.HyperStack.live_region h (FStar.Monotonic.HyperStack.frameOf x)} -> v: a -> FStar.Pervasives.Lemma (ensures FStar.Map.domain (FStar.Monotonic.HyperStack.get_hmap h) == FStar.Map.domain (FStar.Monotonic.HyperStack.get_hmap (FStar.Monotonic.HyperStack.upd h x v)))
{ "end_col": 56, "end_line": 865, "start_col": 3, "start_line": 863 }
Prims.Tot
val rcreate_post_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (b: buffer a) (h0 h1: mem) : Type0
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init
val rcreate_post_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (b: buffer a) (h0 h1: mem) : Type0 let rcreate_post_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (b: buffer a) (h0 h1: mem) : Type0 =
false
null
false
b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.UInt32.t", "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Buffer.unused_in", "FStar.Buffer.live", "Prims.eq2", "Prims.int", "FStar.Buffer.idx", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Buffer.length", "FStar.UInt32.v", "FStar.Set.set", "FStar.Map.domain", "FStar.Monotonic.Heap.heap", "FStar.Monotonic.HyperStack.get_hmap", "FStar.Monotonic.HyperStack.get_tip", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.singleton", "FStar.Monotonic.HyperStack.modifies_ref", "FStar.Set.empty", "Prims.nat", "FStar.Seq.Base.seq", "FStar.Buffer.as_seq", "FStar.Seq.Base.create" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m')
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rcreate_post_common (#a: Type) (r: rid) (init: a) (len: UInt32.t) (b: buffer a) (h0 h1: mem) : Type0
[]
FStar.Buffer.rcreate_post_common
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t -> b: FStar.Buffer.buffer a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
{ "end_col": 45, "end_line": 874, "start_col": 4, "start_line": 868 }
FStar.HyperStack.ST.ST
val rcreate_mm (#a: Type) (r: rid) (init: a) (len: UInt32.t) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true
val rcreate_mm (#a: Type) (r: rid) (init: a) (len: UInt32.t) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) let rcreate_mm (#a: Type) (r: rid) (init: a) (len: UInt32.t) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) =
true
null
false
rcreate_common r init len true
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Monotonic.HyperHeap.rid", "FStar.UInt32.t", "FStar.Buffer.rcreate_common", "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.is_eternal_region", "Prims.l_and", "FStar.Buffer.rcreate_post_common", "Prims.b2t", "FStar.Monotonic.HyperStack.is_mm", "FStar.Buffer.lseq", "FStar.Buffer.max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.content", "FStar.Buffer.freeable" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rcreate_mm (#a: Type) (r: rid) (init: a) (len: UInt32.t) : ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b))
[]
FStar.Buffer.rcreate_mm
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> init: a -> len: FStar.UInt32.t -> FStar.HyperStack.ST.ST (FStar.Buffer.buffer a)
{ "end_col": 34, "end_line": 913, "start_col": 4, "start_line": 913 }
FStar.HyperStack.ST.StackInline
val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b
val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) let createL #a init =
true
null
false
let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content:reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get () in assert (Seq.equal (as_seq h b) (sel h b)); b
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "Prims.list", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Buffer.as_seq", "FStar.Buffer.sel", "FStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Buffer._buffer", "FStar.Buffer.MkBuffer", "FStar.UInt32.__uint_to_t", "FStar.HyperStack.ST.reference", "FStar.Buffer.lseq", "FStar.UInt32.v", "FStar.HyperStack.ST.salloc", "FStar.Heap.trivial_preorder", "FStar.Seq.Properties.seq_of_list", "FStar.HyperStack.ST.mstackref", "FStar.Seq.Base.seq", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.List.Tot.Base.length", "FStar.Seq.Base.length", "FStar.UInt32.t", "FStar.UInt32.uint_to_t" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b))
[]
FStar.Buffer.createL
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
init: Prims.list a -> FStar.HyperStack.ST.StackInline (FStar.Buffer.buffer a)
{ "end_col": 3, "end_line": 856, "start_col": 21, "start_line": 848 }
FStar.HyperStack.ST.ST
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b ))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length)
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b =
true
null
false
let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.Seq.Base.slice", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Buffer.__proj__MkBuffer__item__length", "FStar.UInt.uint_t", "FStar.Buffer.__proj__MkBuffer__item__idx", "FStar.Seq.Base.seq", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.HyperStack.ST.op_Bang", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b ))
[]
FStar.Buffer.to_seq_full
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.ST (FStar.Seq.Base.seq a)
{ "end_col": 32, "end_line": 956, "start_col": 22, "start_line": 953 }
FStar.HyperStack.ST.STL
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) ))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l)
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l =
true
null
false
let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Seq.Base.slice", "Prims.op_Addition", "FStar.UInt.uint_t", "FStar.Buffer.__proj__MkBuffer__item__idx", "FStar.Seq.Base.seq", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.HyperStack.ST.op_Bang", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) ))
[]
FStar.Buffer.to_seq
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> l: FStar.UInt32.t{FStar.UInt32.v l <= FStar.Buffer.length b} -> FStar.HyperStack.ST.STL (FStar.Seq.Base.seq a)
{ "end_col": 25, "end_line": 945, "start_col": 19, "start_line": 942 }
FStar.HyperStack.ST.ST
val rfree (#a: Type) (b: buffer a) : ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content
val rfree (#a: Type) (b: buffer a) : ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) let rfree (#a: Type) (b: buffer a) : ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) =
true
null
false
rfree b.content
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.HyperStack.ST.rfree", "FStar.Buffer.lseq", "FStar.UInt32.v", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Buffer.live", "FStar.Buffer.freeable", "Prims.b2t", "FStar.Monotonic.HyperStack.is_mm", "FStar.Buffer.max_length", "FStar.Buffer.content", "FStar.HyperStack.ST.is_eternal_region", "FStar.Buffer.frameOf", "Prims.eq2", "FStar.Monotonic.HyperStack.free" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rfree (#a: Type) (b: buffer a) : ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0))
[]
FStar.Buffer.rfree
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> FStar.HyperStack.ST.ST Prims.unit
{ "end_col": 19, "end_line": 921, "start_col": 4, "start_line": 921 }
Prims.Tot
val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len
val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len =
false
null
false
assert (v i + v b.idx < pow2 n); MkBuffer b.max_length b.content (i +^ b.idx) len
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Buffer.MkBuffer", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.UInt32.op_Plus_Hat", "FStar.Buffer.__proj__MkBuffer__item__idx", "Prims.unit", "Prims._assert", "Prims.op_LessThan", "Prims.pow2", "FStar.UInt32.n", "Prims.l_and", "FStar.Buffer.includes", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len})
[]
FStar.Buffer.sub
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> i: FStar.UInt32.t -> len: FStar.UInt32.t{FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b} -> b': FStar.Buffer.buffer a {FStar.Buffer.includes b b' /\ FStar.Buffer.length b' == FStar.UInt32.v len}
{ "end_col": 50, "end_line": 1028, "start_col": 2, "start_line": 1027 }
FStar.HyperStack.ST.Stack
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n)))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n)
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n =
true
null
false
let s = !b.content in Seq.index s (v b.idx + v n)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Seq.Base.index", "Prims.op_Addition", "FStar.Buffer.__proj__MkBuffer__item__idx", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.HyperStack.ST.op_Bang", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n)))
[]
FStar.Buffer.index
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} -> FStar.HyperStack.ST.Stack a
{ "end_col": 29, "end_line": 964, "start_col": 18, "start_line": 962 }
FStar.HyperStack.ST.Stack
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z =
true
null
false
let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get () in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "FStar.Seq.Properties.upd_slice", "FStar.Buffer.idx", "Prims.op_Addition", "FStar.Buffer.length", "FStar.UInt32.v", "Prims.unit", "FStar.Seq.Base.lemma_eq_intro", "FStar.Buffer.as_seq", "FStar.Seq.Base.slice", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Buffer.lemma_aux", "FStar.HyperStack.ST.op_Colon_Equals", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "FStar.Buffer.__proj__MkBuffer__item__idx", "FStar.HyperStack.ST.op_Bang" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
[]
FStar.Buffer.upd
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t -> z: a -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 53, "end_line": 1021, "start_col": 18, "start_line": 1013 }
FStar.Pervasives.Lemma
val lemma_aux_0 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) (bb: buffer tt) : Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm ()
val lemma_aux_0 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) (bb: buffer tt) : Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) let lemma_aux_0 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) (bb: buffer tt) : Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) =
false
null
true
Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm ()
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_mm", "Prims.unit", "FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_preorders", "Prims.l_and", "FStar.Buffer.live", "FStar.Buffer.disjoint", "Prims.squash", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "FStar.Buffer.as_seq", "FStar.Monotonic.HyperStack.upd", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.Seq.Base.upd", "FStar.Buffer.sel", "Prims.op_Addition", "FStar.Buffer.idx", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_aux_0 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) (bb: buffer tt) : Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))
[]
FStar.Buffer.lemma_aux_0
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} -> z: a -> h0: FStar.Monotonic.HyperStack.mem -> tt: Type0 -> bb: FStar.Buffer.buffer tt -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b /\ FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb) (ensures FStar.Buffer.live h0 b /\ FStar.Buffer.live h0 bb /\ (let h1 = FStar.Monotonic.HyperStack.upd h0 (MkBuffer?.content b) (FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z) in FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb))
{ "end_col": 44, "end_line": 975, "start_col": 4, "start_line": 974 }
Prims.Tot
val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'})
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i =
false
null
false
MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Buffer.__proj__MkBuffer__item__idx", "Prims.pow2", "FStar.UInt32.n", "Prims.op_LessThanOrEqual", "FStar.Buffer.__proj__MkBuffer__item__length", "FStar.Buffer.MkBuffer", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.UInt32.op_Plus_Hat", "FStar.UInt32.op_Subtraction_Hat", "FStar.Buffer.includes" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'})
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'})
[]
FStar.Buffer.offset
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> i: FStar.UInt32.t { FStar.UInt32.v i + FStar.UInt32.v (MkBuffer?.idx b) < Prims.pow2 FStar.UInt32.n /\ FStar.UInt32.v i <= FStar.UInt32.v (MkBuffer?.length b) } -> b': FStar.Buffer.buffer a {FStar.Buffer.includes b b'}
{ "end_col": 62, "end_line": 1072, "start_col": 2, "start_line": 1072 }
FStar.Pervasives.Lemma
val lemma_sub_spec' (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h
val lemma_sub_spec' (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] let lemma_sub_spec' (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] =
false
null
true
lemma_sub_spec b i len h
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "Prims.op_Addition", "FStar.Monotonic.HyperStack.mem", "FStar.Buffer.lemma_sub_spec", "Prims.unit", "FStar.Buffer.live", "Prims.squash", "FStar.Buffer.sub", "Prims.eq2", "FStar.Seq.Base.seq", "FStar.Buffer.as_seq", "FStar.Seq.Base.slice", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_sub_spec' (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))]
[]
FStar.Buffer.lemma_sub_spec'
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> i: FStar.UInt32.t -> len: FStar.UInt32.t { FStar.UInt32.v len <= FStar.Buffer.length b /\ FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b } -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h b) (ensures FStar.Buffer.live h (FStar.Buffer.sub b i len) /\ FStar.Buffer.as_seq h (FStar.Buffer.sub b i len) == FStar.Seq.Base.slice (FStar.Buffer.as_seq h b) (FStar.UInt32.v i) (FStar.UInt32.v i + FStar.UInt32.v len)) [SMTPat (FStar.Buffer.live h (FStar.Buffer.sub b i len))]
{ "end_col": 28, "end_line": 1066, "start_col": 4, "start_line": 1066 }
FStar.Pervasives.Lemma
val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0
val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 =
false
null
true
lemma_aux_2 b n z h0
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "FStar.Buffer.lemma_aux_2", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) ))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))]
[]
FStar.Buffer.lemma_aux
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} -> z: a -> h0: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b) (ensures FStar.Buffer.live h0 b /\ FStar.Buffer.modifies_1 b h0 (FStar.Monotonic.HyperStack.upd h0 (MkBuffer?.content b) (FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z) )) [ SMTPat (FStar.Monotonic.HyperStack.upd h0 (MkBuffer?.content b) (FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z) ) ]
{ "end_col": 48, "end_line": 1006, "start_col": 28, "start_line": 1006 }
FStar.Pervasives.Lemma
val lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
val lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) let lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) =
false
null
true
let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "FStar.Classical.forall_intro", "Prims.l_imp", "Prims.l_and", "FStar.Buffer.live", "FStar.Buffer.disjoint", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "FStar.Buffer.as_seq", "FStar.Monotonic.HyperStack.upd", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.Seq.Base.upd", "FStar.Buffer.sel", "Prims.op_Addition", "FStar.Buffer.idx", "FStar.Classical.move_requires", "FStar.Buffer.lemma_aux_0", "Prims.unit", "Prims.squash", "Prims.l_Forall", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_aux_1 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) (tt: Type) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))))
[]
FStar.Buffer.lemma_aux_1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} -> z: a -> h0: FStar.Monotonic.HyperStack.mem -> tt: Type0 -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b) (ensures FStar.Buffer.live h0 b /\ (forall (bb: FStar.Buffer.buffer tt). FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb ==> (let h1 = FStar.Monotonic.HyperStack.upd h0 (MkBuffer?.content b) (FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z) in FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb)))
{ "end_col": 58, "end_line": 986, "start_col": 4, "start_line": 985 }
FStar.HyperStack.ST.Stack
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Array_Assignment #a b n z = upd #a b n z
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let op_Array_Assignment #a b n z =
true
null
false
upd #a b n z
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "FStar.Buffer.upd", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) (** Corresponds to memcmp for `eqtype` *) val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) let rec eqb #a b1 b2 len = if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false (** // Defining operators for buffer accesses as specified at // https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence // *) (* JP: if the [val] is not specified, there's an issue with these functions // * taking an extra unification parameter at extraction-time... *) val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let op_Array_Access #a b n = index #a b n val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z ))
[]
FStar.Buffer.op_Array_Assignment
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t -> z: a -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 47, "end_line": 1147, "start_col": 35, "start_line": 1147 }
FStar.Pervasives.Lemma
val lemma_sub_spec (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
val lemma_sub_spec (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] let lemma_sub_spec (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] =
false
null
true
Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "Prims.op_Addition", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.lemma_eq_intro", "FStar.Buffer.as_seq", "FStar.Buffer.sub", "FStar.Seq.Base.slice", "Prims.unit", "FStar.Buffer.live", "Prims.squash", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Buffer.includes", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "Prims.Nil" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len)))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_sub_spec (#a: Type) (b: buffer a) (i: UInt32.t) (len: UInt32.t{v len <= length b /\ v i + v len <= length b}) (h: _) : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)]
[]
FStar.Buffer.lemma_sub_spec
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> i: FStar.UInt32.t -> len: FStar.UInt32.t { FStar.UInt32.v len <= FStar.Buffer.length b /\ FStar.UInt32.v i + FStar.UInt32.v len <= FStar.Buffer.length b } -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h b) (ensures FStar.Buffer.live h (FStar.Buffer.sub b i len) /\ FStar.Buffer.as_seq h (FStar.Buffer.sub b i len) == FStar.Seq.Base.slice (FStar.Buffer.as_seq h b) (FStar.UInt32.v i) (FStar.UInt32.v i + FStar.UInt32.v len)) [SMTPat (FStar.Buffer.sub b i len); SMTPat (FStar.Buffer.live h b)]
{ "end_col": 92, "end_line": 1056, "start_col": 4, "start_line": 1056 }
Prims.Tot
val split (#t: _) (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let split #t (b:buffer t) (i:UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) = sub b 0ul i, offset b i
val split (#t: _) (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) let split #t (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t) =
false
null
false
sub b 0ul i, offset b i
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "total" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Pervasives.Native.Mktuple2", "FStar.Buffer.sub", "FStar.UInt32.__uint_to_t", "FStar.Buffer.offset", "FStar.Pervasives.Native.tuple2" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) (** Corresponds to memcmp for `eqtype` *) val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) let rec eqb #a b1 b2 len = if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false (** // Defining operators for buffer accesses as specified at // https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence // *) (* JP: if the [val] is not specified, there's an issue with these functions // * taking an extra unification parameter at extraction-time... *) val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let op_Array_Access #a b n = index #a b n val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let op_Array_Assignment #a b n z = upd #a b n z let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma (requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2)) (ensures (modifies_one (frameOf b) h0 h2)) [SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)] = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (** Corresponds to memcpy *) val blit: #t:Type -> a:buffer t -> idx_a:UInt32.t{v idx_a <= length a} -> b:buffer t{disjoint a b} -> idx_b:UInt32.t{v idx_b <= length b} -> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b} -> Stack unit (requires (fun h -> live h a /\ live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) == Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len) /\ Seq.slice (as_seq h1 b) 0 (v idx_b) == Seq.slice (as_seq h0 b) 0 (v idx_b) /\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) == Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) )) let rec blit #t a idx_a b idx_b len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in blit #t a idx_a b idx_b len'; let z = a.(idx_a +^ len') in b.(idx_b +^ len') <- z; let h1 = HST.get() in Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len'); Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b)); Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b)) end (** Corresponds to memset *) val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) == Seq.slice (as_seq h0 b) (v len) (length b) )) let rec fill #t b z len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in fill #t b z len'; b.(len') <- z; let h = HST.get() in Seq.snoc_slice_index (as_seq h b) 0 (v len'); Seq.lemma_tail_slice (as_seq h b) (v len') (length b) end; let h1 = HST.get() in Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val split (#t: _) (b: buffer t) (i: UInt32.t{v i <= length b}) : Tot (buffer t * buffer t)
[]
FStar.Buffer.split
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer t -> i: FStar.UInt32.t{FStar.UInt32.v i <= FStar.Buffer.length b} -> FStar.Buffer.buffer t * FStar.Buffer.buffer t
{ "end_col": 27, "end_line": 1216, "start_col": 4, "start_line": 1216 }
FStar.Pervasives.Lemma
val lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt: Type) (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0))
val lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt: Type) (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) let lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt: Type) (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) =
false
null
true
let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "FStar.Classical.forall_intro", "Prims.l_imp", "FStar.Buffer.live", "Prims.l_and", "Prims.l_Forall", "FStar.Buffer.disjoint", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "FStar.Buffer.as_seq", "FStar.Monotonic.HyperStack.upd", "FStar.Buffer.lseq", "FStar.Buffer.__proj__MkBuffer__item__max_length", "FStar.Heap.trivial_preorder", "FStar.Buffer.__proj__MkBuffer__item__content", "FStar.Seq.Base.upd", "FStar.Buffer.sel", "Prims.op_Addition", "FStar.Buffer.idx", "FStar.Classical.move_requires", "FStar.Buffer.lemma_aux_1", "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_aux_2 (#a: Type) (b: buffer a) (n: UInt32.t{v n < length b}) (z: a) (h0: mem) : Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt: Type) (bb: buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))))
[]
FStar.Buffer.lemma_aux_2
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer a -> n: FStar.UInt32.t{FStar.UInt32.v n < FStar.Buffer.length b} -> z: a -> h0: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Buffer.live h0 b) (ensures FStar.Buffer.live h0 b /\ (forall (tt: Type0) (bb: FStar.Buffer.buffer tt). FStar.Buffer.live h0 bb /\ FStar.Buffer.disjoint b bb ==> (let h1 = FStar.Monotonic.HyperStack.upd h0 (MkBuffer?.content b) (FStar.Seq.Base.upd (FStar.Buffer.sel h0 b) (FStar.Buffer.idx b + FStar.UInt32.v n) z) in FStar.Buffer.as_seq h0 bb == FStar.Buffer.as_seq h1 bb)))
{ "end_col": 55, "end_line": 998, "start_col": 4, "start_line": 997 }
FStar.Pervasives.Lemma
val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h =
false
null
true
Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len))
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[ "lemma" ]
[ "Prims.eqtype", "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.lemma_eq_intro", "FStar.Buffer.as_seq", "FStar.Buffer.sub", "FStar.UInt32.__uint_to_t", "Prims.unit" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))]
[]
FStar.Buffer.eq_lemma1
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b1: FStar.Buffer.buffer a -> b2: FStar.Buffer.buffer a -> len: FStar.UInt32.t { FStar.UInt32.v len <= FStar.Buffer.length b1 /\ FStar.UInt32.v len <= FStar.Buffer.length b2 } -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires forall (j: Prims.nat). j < FStar.UInt32.v len ==> FStar.Buffer.get h b1 j == FStar.Buffer.get h b2 j) (ensures FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len)) [SMTPat (FStar.Buffer.equal h (FStar.Buffer.sub b1 0ul len) h (FStar.Buffer.sub b2 0ul len))]
{ "end_col": 76, "end_line": 1094, "start_col": 2, "start_line": 1094 }
FStar.HyperStack.ST.Stack
val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) == Seq.slice (as_seq h0 b) (v len) (length b) ))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec fill #t b z len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in fill #t b z len'; b.(len') <- z; let h = HST.get() in Seq.snoc_slice_index (as_seq h b) 0 (v len'); Seq.lemma_tail_slice (as_seq h b) (v len') (length b) end; let h1 = HST.get() in Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) == Seq.slice (as_seq h0 b) (v len) (length b) )) let rec fill #t b z len =
true
null
false
let h0 = HST.get () in if len =^ 0ul then () else (let len' = len -^ 1ul in fill #t b z len'; b.(len') <- z; let h = HST.get () in Seq.snoc_slice_index (as_seq h b) 0 (v len'); Seq.lemma_tail_slice (as_seq h b) (v len') (length b)); let h1 = HST.get () in Seq.lemma_eq_intro (Seq.slice (as_seq h1 b) 0 (v len)) (Seq.create (v len) z)
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.Seq.Base.lemma_eq_intro", "FStar.Seq.Base.slice", "FStar.Buffer.as_seq", "FStar.Seq.Base.create", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.UInt32.op_Equals_Hat", "FStar.UInt32.__uint_to_t", "Prims.bool", "FStar.Seq.Properties.lemma_tail_slice", "FStar.Seq.Properties.snoc_slice_index", "FStar.Buffer.op_Array_Assignment", "FStar.Buffer.fill", "FStar.UInt32.op_Subtraction_Hat" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) (** Corresponds to memcmp for `eqtype` *) val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) let rec eqb #a b1 b2 len = if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false (** // Defining operators for buffer accesses as specified at // https://github.com/FStarLang/FStar/wiki/Parsing-and-operator-precedence // *) (* JP: if the [val] is not specified, there's an issue with these functions // * taking an extra unification parameter at extraction-time... *) val op_Array_Access: #a:Type -> b:buffer a -> n:UInt32.t{v n<length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let op_Array_Access #a b n = index #a b n val op_Array_Assignment: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let op_Array_Assignment #a b n z = upd #a b n z let lemma_modifies_one_trans_1 (#a:Type) (b:buffer a) (h0:mem) (h1:mem) (h2:mem): Lemma (requires (modifies_one (frameOf b) h0 h1 /\ modifies_one (frameOf b) h1 h2)) (ensures (modifies_one (frameOf b) h0 h2)) [SMTPat (modifies_one (frameOf b) h0 h1); SMTPat (modifies_one (frameOf b) h1 h2)] = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (** Corresponds to memcpy *) val blit: #t:Type -> a:buffer t -> idx_a:UInt32.t{v idx_a <= length a} -> b:buffer t{disjoint a b} -> idx_b:UInt32.t{v idx_b <= length b} -> len:UInt32.t{v idx_a + v len <= length a /\ v idx_b + v len <= length b} -> Stack unit (requires (fun h -> live h a /\ live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) (v idx_b) (v idx_b + v len) == Seq.slice (as_seq h0 a) (v idx_a) (v idx_a + v len) /\ Seq.slice (as_seq h1 b) 0 (v idx_b) == Seq.slice (as_seq h0 b) 0 (v idx_b) /\ Seq.slice (as_seq h1 b) (v idx_b+v len) (length b) == Seq.slice (as_seq h0 b) (v idx_b+v len) (length b) )) let rec blit #t a idx_a b idx_b len = let h0 = HST.get () in if len =^ 0ul then () else begin let len' = len -^ 1ul in blit #t a idx_a b idx_b len'; let z = a.(idx_a +^ len') in b.(idx_b +^ len') <- z; let h1 = HST.get() in Seq.snoc_slice_index (as_seq h1 b) (v idx_b) (v idx_b + v len'); Seq.cons_head_tail (Seq.slice (as_seq h0 b) (v idx_b + v len') (length b)); Seq.cons_head_tail (Seq.slice (as_seq h1 b) (v idx_b + v len') (length b)) end (** Corresponds to memset *) val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) ==
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fill: #t:Type -> b:buffer t -> z:t -> len:UInt32.t{v len <= length b} -> Stack unit (requires (fun h -> live h b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1 /\ Seq.slice (as_seq h1 b) 0 (v len) == Seq.create (v len) z /\ Seq.slice (as_seq h1 b) (v len) (length b) == Seq.slice (as_seq h0 b) (v len) (length b) ))
[ "recursion" ]
FStar.Buffer.fill
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: FStar.Buffer.buffer t -> z: t -> len: FStar.UInt32.t{FStar.UInt32.v len <= FStar.Buffer.length b} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 79, "end_line": 1212, "start_col": 25, "start_line": 1199 }
FStar.HyperStack.ST.ST
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int32", "short_module": "Int32" }, { "abbrev": false, "full_module": "FStar.UInt32", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec eqb #a b1 b2 len = if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len)))) let rec eqb #a b1 b2 len =
true
null
false
if len =^ 0ul then true else let len' = len -^ 1ul in if index b1 len' = index b2 len' then eqb b1 b2 len' else false
{ "checked_file": "FStar.Buffer.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.TSet.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int32.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Heap.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Buffer.fst" }
[]
[ "Prims.eqtype", "FStar.Buffer.buffer", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Buffer.length", "FStar.UInt32.op_Equals_Hat", "FStar.UInt32.__uint_to_t", "Prims.bool", "FStar.Buffer.eqb", "Prims.op_Equality", "FStar.Buffer.index", "FStar.UInt32.op_Subtraction_Hat" ]
[]
(* 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.Buffer open FStar.Seq open FStar.UInt32 module Int32 = FStar.Int32 open FStar.HyperStack open FStar.HyperStack.ST open FStar.Ghost module HS = FStar.HyperStack module HST = FStar.HyperStack.ST #set-options "--initial_fuel 0 --max_fuel 0" //17-01-04 usage? move to UInt? let lemma_size (x:int) : Lemma (requires (UInt.size x n)) (ensures (x >= 0)) [SMTPat (UInt.size x n)] = () let lseq (a: Type) (l: nat) : Type = (s: seq a { Seq.length s == l } ) (* Buffer general type, fully implemented on FStar's arrays *) noeq private type _buffer (a:Type) = | MkBuffer: max_length:UInt32.t -> content:reference (lseq a (v max_length)) -> idx:UInt32.t -> length:UInt32.t{v idx + v length <= v max_length} -> _buffer a (* Exposed buffer type *) type buffer (a:Type) = _buffer a (* Ghost getters for specifications *) // TODO: remove `contains` after replacing all uses with `live` let contains #a h (b:buffer a) : GTot Type0 = HS.contains h b.content let unused_in #a (b:buffer a) h : GTot Type0 = HS.unused_in b.content h (* In most cases `as_seq` should be used instead of this one. *) let sel #a h (b:buffer a) : GTot (seq a) = HS.sel h b.content let max_length #a (b:buffer a) : GTot nat = v b.max_length let length #a (b:buffer a) : GTot nat = v b.length let idx #a (b:buffer a) : GTot nat = v b.idx //17-01-04 rename to container or ref? let content #a (b:buffer a) : GTot (reference (lseq a (max_length b))) = b.content (* Lifting from buffer to reference *) let as_ref #a (b:buffer a) = as_ref (content b) let as_addr #a (b:buffer a) = as_addr (content b) let frameOf #a (b:buffer a) : GTot HS.rid = HS.frameOf (content b) (* Liveliness condition, necessary for any computation on the buffer *) let live #a (h:mem) (b:buffer a) : GTot Type0 = HS.contains h b.content let unmapped_in #a (b:buffer a) (h:mem) : GTot Type0 = unused_in b h val recall: #a:Type -> b:buffer a{is_eternal_region (frameOf b) /\ not (is_mm b.content)} -> Stack unit (requires (fun m -> True)) (ensures (fun m0 _ m1 -> m0 == m1 /\ live m1 b)) let recall #a b = recall b.content (* Ghostly access an element of the array, or the full underlying sequence *) let as_seq #a h (b:buffer a) : GTot (s:seq a{Seq.length s == length b}) = Seq.slice (sel h b) (idx b) (idx b + length b) let get #a h (b:buffer a) (i:nat{i < length b}) : GTot a = Seq.index (as_seq h b) i (* Equality predicate on buffer contents, without quantifiers *) //17-01-04 revise comment? rename? let equal #a h (b:buffer a) h' (b':buffer a) : GTot Type0 = as_seq h b == as_seq h' b' (* y is included in x / x contains y *) let includes #a (x:buffer a) (y:buffer a) : GTot Type0 = x.max_length == y.max_length /\ x.content === y.content /\ idx y >= idx x /\ idx x + length x >= idx y + length y let includes_live #a h (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y)) (ensures (live h x <==> live h y)) = () let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a) : Lemma (requires (x `includes` y /\ as_seq h1 x == as_seq h2 x)) (ensures (as_seq h1 y == as_seq h2 y)) = Seq.slice_slice (sel h1 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y); Seq.slice_slice (sel h2 x) (idx x) (idx x + length x) (idx y - idx x) (idx y - idx x + length y) let includes_trans #a (x y z: buffer a) : Lemma (requires (x `includes` y /\ y `includes` z)) (ensures (x `includes` z)) = () (* Disjointness between two buffers *) let disjoint #a #a' (x:buffer a) (y:buffer a') : GTot Type0 = frameOf x =!= frameOf y \/ as_addr x =!= as_addr y \/ (a == a' /\ as_addr x == as_addr y /\ frameOf x == frameOf y /\ x.max_length == y.max_length /\ (idx x + length x <= idx y \/ idx y + length y <= idx x)) (* Disjointness is symmetric *) let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma (requires True) (ensures (disjoint x y <==> disjoint y x)) [SMTPat (disjoint x y)] = () let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint subx y); SMTPat (includes x subx)] = () let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma (requires (includes x subx /\ disjoint x y)) (ensures (disjoint subx y)) [SMTPat (disjoint y subx); SMTPat (includes x subx)] = () val lemma_live_disjoint: #a:Type -> #a':Type -> h:mem -> b:buffer a -> b':buffer a' -> Lemma (requires (live h b /\ b' `unused_in` h)) (ensures (disjoint b b')) [SMTPat (disjoint b b'); SMTPat (live h b)] let lemma_live_disjoint #a #a' h b b' = () (* Heterogeneous buffer type *) noeq type abuffer = | Buff: #t:Type -> b:buffer t -> abuffer (* let empty : TSet.set abuffer = TSet.empty #abuffer *) let only #t (b:buffer t) : Tot (TSet.set abuffer) = FStar.TSet.singleton (Buff #t b) (* let op_Plus_Plus #a s (b:buffer a) : Tot (TSet.set abuffer) = TSet.union s (only b) *) (* let op_Plus_Plus_Plus set1 set2 : Tot (TSet.set abuffer) = FStar.TSet.union set1 set2 *) let op_Bang_Bang = TSet.singleton let op_Plus_Plus = TSet.union (* Maps a set of buffer to the set of their references *) assume val arefs: TSet.set abuffer -> Tot (Set.set nat) assume Arefs_def: forall (x:nat) (s:TSet.set abuffer). {:pattern (Set.mem x (arefs s))} Set.mem x (arefs s) <==> (exists (y:abuffer). TSet.mem y s /\ as_addr y.b == x) val lemma_arefs_1: s:TSet.set abuffer -> Lemma (requires (s == TSet.empty #abuffer)) (ensures (arefs s == Set.empty #nat)) [SMTPat (arefs s)] let lemma_arefs_1 s = Set.lemma_equal_intro (arefs s) (Set.empty) val lemma_arefs_2: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires True) (ensures (arefs (s1 ++ s2) == Set.union (arefs s1) (arefs s2))) [SMTPatOr [ [SMTPat (arefs (s2 ++ s1))]; [SMTPat (arefs (s1 ++ s2))] ]] let lemma_arefs_2 s1 s2 = Set.lemma_equal_intro (arefs (s1 ++ s2)) (Set.union (arefs s1) (arefs s2)) val lemma_arefs_3: s1:TSet.set abuffer -> s2:TSet.set abuffer -> Lemma (requires (TSet.subset s1 s2)) (ensures (Set.subset (arefs s1) (arefs s2))) let lemma_arefs_3 s1 s2 = () (* General disjointness predicate between a buffer and a set of heterogeneous buffers *) let disjoint_from_bufs #a (b:buffer a) (bufs:TSet.set abuffer) = forall b'. TSet.mem b' bufs ==> disjoint b b'.b (* General disjointness predicate between a buffer and a set of heterogeneous references *) let disjoint_from_refs #a (b:buffer a) (set:Set.set nat) = ~(Set.mem (as_addr b) set) (* Similar but specialized disjointness predicates *) let disjoint_1 a b = disjoint a b let disjoint_2 a b b' = disjoint a b /\ disjoint a b' let disjoint_3 a b b' b'' = disjoint a b /\ disjoint a b' /\ disjoint a b'' let disjoint_4 a b b' b'' b''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' let disjoint_5 a b b' b'' b''' b'''' = disjoint a b /\ disjoint a b' /\ disjoint a b'' /\ disjoint a b''' /\ disjoint a b'''' let disjoint_ref_1 (#t:Type) (#u:Type) (a:buffer t) (r:reference u) = frameOf a =!= HS.frameOf r \/ as_addr a =!= HS.as_addr r let disjoint_ref_2 a r r' = disjoint_ref_1 a r /\ disjoint_ref_1 a r' let disjoint_ref_3 a r r' r'' = disjoint_ref_1 a r /\ disjoint_ref_2 a r' r'' let disjoint_ref_4 a r r' r'' r''' = disjoint_ref_1 a r /\ disjoint_ref_3 a r' r'' r''' let disjoint_ref_5 a r r' r'' r''' r'''' = disjoint_ref_1 a r /\ disjoint_ref_4 a r' r'' r''' r'''' val disjoint_only_lemma: #a:Type -> #a':Type -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint b b')) (ensures (disjoint_from_bufs b (only b'))) let disjoint_only_lemma #a #a' b b' = () (* Fully general modifies clause *) let modifies_bufs_and_refs (bufs:TSet.set abuffer) (refs:Set.set nat) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (Set.union (arefs bufs) refs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs /\ disjoint_from_refs b refs) ==> equal h b h' b /\ live h' b))) (* Fully general modifies clause for buffer sets *) let modifies_buffers (bufs:TSet.set abuffer) h h' : GTot Type0 = (forall rid. Set.mem rid (Map.domain (HS.get_hmap h)) ==> (HS.modifies_ref rid (arefs bufs) h h' /\ (forall (#a:Type) (b:buffer a). {:pattern (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs)} (frameOf b == rid /\ live h b /\ disjoint_from_bufs b bufs ==> equal h b h' b /\ live h' b)))) (* General modifies clause for buffers only *) let modifies_bufs rid buffs h h' = modifies_ref rid (arefs buffs) h h' /\ (forall (#a:Type) (b:buffer a). (frameOf b == rid /\ live h b /\ disjoint_from_bufs b buffs) ==> equal h b h' b /\ live h' b) let modifies_none h h' = HS.get_tip h' == HS.get_tip h /\ HS.modifies_transitively Set.empty h h' (* Specialized clauses for small numbers of buffers *) let modifies_buf_0 rid h h' = modifies_ref rid (Set.empty #nat) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb) ==> equal h bb h' bb /\ live h' bb) let modifies_buf_1 (#t:Type) rid (b:buffer t) h h' = //would be good to drop the rid argument on these, since they can be computed from the buffers modifies_ref rid (Set.singleton (Heap.addr_of (as_ref b))) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb) ==> equal h bb h' bb /\ live h' bb) let to_set_2 (n1:nat) (n2:nat) :Set.set nat = Set.union (Set.singleton n1) (Set.singleton n2) let modifies_buf_2 (#t:Type) (#t':Type) rid (b:buffer t) (b':buffer t') h h' = modifies_ref rid (to_set_2 (as_addr b) (as_addr b')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_3 (n1:nat) (n2:nat) (n3:nat) :Set.set nat = Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3) let modifies_buf_3 (#t:Type) (#t':Type) (#t'':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') h h' = modifies_ref rid (to_set_3 (as_addr b) (as_addr b') (as_addr b'')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb) ==> equal h bb h' bb /\ live h' bb) let to_set_4 (n1:nat) (n2:nat) (n3:nat) (n4:nat) :Set.set nat = Set.union (Set.union (Set.union (Set.singleton n1) (Set.singleton n2)) (Set.singleton n3)) (Set.singleton n4) let modifies_buf_4 (#t:Type) (#t':Type) (#t'':Type) (#t''':Type) rid (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') h h' = modifies_ref rid (to_set_4 (as_addr b) (as_addr b') (as_addr b'') (as_addr b''')) h h' /\ (forall (#tt:Type) (bb:buffer tt). (frameOf bb == rid /\ live h bb /\ disjoint b bb /\ disjoint b' bb /\ disjoint b'' bb /\ disjoint b''' bb) ==> equal h bb h' bb /\ live h' bb) (* General lemmas for the modifies_bufs clause *) let lemma_modifies_bufs_trans rid bufs h0 h1 h2 : Lemma (requires (modifies_bufs rid bufs h0 h1 /\ modifies_bufs rid bufs h1 h2)) (ensures (modifies_bufs rid bufs h0 h2)) [SMTPat (modifies_bufs rid bufs h0 h1); SMTPat (modifies_bufs rid bufs h1 h2)] = () let lemma_modifies_bufs_sub rid bufs subbufs h0 h1 : Lemma (requires (TSet.subset subbufs bufs /\ modifies_bufs rid subbufs h0 h1)) (ensures (modifies_bufs rid bufs h0 h1)) [SMTPat (modifies_bufs rid subbufs h0 h1); SMTPat (TSet.subset subbufs bufs)] = () val lemma_modifies_bufs_subset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (disjoint_from_bufs b (bufs ++ (only b')) )) (ensures (disjoint_from_bufs b bufs)) [SMTPat (modifies_bufs (HS.get_tip h0) (bufs ++ (only b')) h0 h1); SMTPat (live h0 b)] let lemma_modifies_bufs_subset #a #a' h0 h1 bufs b b' = () val lemma_modifies_bufs_superset: #a:Type -> #a':Type -> h0:mem -> h1:mem -> bufs:TSet.set abuffer -> b:buffer a -> b':buffer a' -> Lemma (requires (b' `unused_in` h0 /\ live h0 b /\ disjoint_from_bufs b bufs)) (ensures (disjoint_from_bufs b (bufs ++ (only b')))) [SMTPat (modifies_bufs (HS.get_tip h0) bufs h0 h1); SMTPat (b' `unmapped_in` h0); SMTPat (live h0 b)] let lemma_modifies_bufs_superset #a #a' h0 h1 bufs b b' = () (* Specialized lemmas *) let modifies_trans_0_0 (rid:rid) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_0 rid h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_1_0 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_0_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1 (#t:Type) (rid:rid) (b:buffer t) (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_1 rid b h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_1_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_1 rid b' h1 h2)] = () let modifies_trans_2_0 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 rid h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_0 rid h1 h2)] = () let modifies_trans_2_1 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_2_1' (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b' b h0 h1 /\ modifies_buf_1 rid b h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b' b h0 h1); SMTPat (modifies_buf_1 rid b h1 h2)] = () let modifies_trans_0_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_0 rid h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_0 rid h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_1_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_1 rid b h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_1 rid b h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_2_2 (#t:Type) (#t':Type) (rid:rid) (b:buffer t) (b':buffer t') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_2 rid b b' h1 h2)) (ensures (modifies_buf_2 rid b b' h0 h2)) [SMTPat (modifies_buf_2 rid b b' h0 h1); SMTPat (modifies_buf_2 rid b b' h1 h2)] = () let modifies_trans_3_3 (#t #t' #t'':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_buf_3 rid b b' b'' h1 h2)) (ensures (modifies_buf_3 rid b b' b'' h0 h2)) [SMTPat (modifies_buf_3 rid b b' b'' h0 h1); SMTPat (modifies_buf_3 rid b b' b'' h1 h2)] = () let modifies_trans_4_4 (#t #t' #t'' #t''':Type) (rid:rid) (b:buffer t) (b':buffer t') (b'':buffer t'') (b''':buffer t''') (h0 h1 h2:mem) : Lemma (requires (modifies_buf_4 rid b b' b'' b''' h0 h1 /\ modifies_buf_4 rid b b' b'' b''' h1 h2)) (ensures (modifies_buf_4 rid b b' b'' b''' h0 h2)) [SMTPat (modifies_buf_4 rid b b' b'' b''' h0 h1); SMTPat (modifies_buf_4 rid b b' b'' b''' h1 h2)] = () (* TODO: complete with specialized versions of every general lemma *) (* Modifies clauses that do not change the shape of the HyperStack ((HS.get_tip h1) = (HS.get_tip h0)) *) (* NB: those clauses are made abstract in order to make verification faster // Lemmas follow to allow the programmer to make use of the real definition // of those predicates in a general setting *) let modifies_0 (h0 h1:mem) :Type0 = modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* This one is very generic: it says // * - some references have changed in the frame of b, but // * - among all buffers in this frame, b is the only one that changed. *) let modifies_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 let modifies_2_1 (#a:Type) (b:buffer a) (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))) let modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))) let modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))) let modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') (h0 h1:mem) :Type0 = HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))) let modifies_region (rid:rid) (bufs:TSet.set abuffer) (h0 h1:mem) :Type0 = modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1 (* Lemmas introducing the 'modifies' predicates *) let lemma_intro_modifies_0 h0 h1 : Lemma (requires (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_0 h0 h1)) = () let lemma_intro_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_1 b h0 h1)) = () let lemma_intro_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) (ensures (modifies_2_1 b h0 h1)) = () let lemma_intro_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 ))))) (ensures (modifies_2 b b' h0 h1)) = () let lemma_intro_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1))))) (ensures (modifies_3 b b' b'' h0 h1)) = () let lemma_intro_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1))))) (ensures (modifies_3_2 b b' h0 h1)) = () let lemma_intro_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) (ensures (modifies_region rid bufs h0 h1)) = () (* Lemmas revealing the content of the specialized modifies clauses in order to // be able to generalize them if needs be. *) let lemma_reveal_modifies_0 h0 h1 : Lemma (requires (modifies_0 h0 h1)) (ensures (modifies_one (HS.get_tip h0) h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_1 b h0 h1)) (ensures (let rid = frameOf b in modifies_one rid h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () let lemma_reveal_modifies_2_1 (#a:Type) (b:buffer a) h0 h1 : Lemma (requires (modifies_2_1 b h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in ((rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 ))))) = () let lemma_reveal_modifies_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid =!= rid' /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 )) ))) = () let lemma_reveal_modifies_3 (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 : Lemma (requires (modifies_3 b b' b'' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in let rid'' = frameOf b'' in ((rid == rid' /\ rid' == rid'' /\ modifies_buf_3 rid b b' b'' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid =!= rid' /\ rid' == rid'' /\ modifies_buf_2 rid' b' b'' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid'')) h0 h1 ) \/ (rid == rid'' /\ rid' =!= rid'' /\ modifies_buf_2 rid b b'' h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton rid')) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= rid'' /\ rid =!= rid'' /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton rid'')) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid'' b'' h0 h1)) ))) = () let lemma_reveal_modifies_3_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires (modifies_3_2 b b' h0 h1)) (ensures ( HS.get_tip h0 == HS.get_tip h1 /\ (let rid = frameOf b in let rid' = frameOf b' in ((rid == rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_one rid h0 h1) \/ (rid == rid' /\ rid' =!= HS.get_tip h0 /\ modifies_buf_2 rid b b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid == HS.get_tip h0 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ HS.modifies (Set.union (Set.singleton rid') (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' == HS.get_tip h0 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ HS.modifies (Set.union (Set.singleton rid) (Set.singleton (HS.get_tip h0))) h0 h1 ) \/ (rid =!= rid' /\ rid' =!= HS.get_tip h0 /\ rid =!= HS.get_tip h0 /\ HS.modifies (Set.union (Set.union (Set.singleton rid) (Set.singleton rid')) (Set.singleton (HS.get_tip h0))) h0 h1 /\ modifies_buf_1 rid b h0 h1 /\ modifies_buf_1 rid' b' h0 h1 /\ modifies_buf_0 (HS.get_tip h0) h0 h1)) ))) = () let lemma_reveal_modifies_region (rid:rid) bufs h0 h1 : Lemma (requires (modifies_region rid bufs h0 h1)) (ensures (modifies_one rid h0 h1 /\ modifies_bufs rid bufs h0 h1 /\ HS.get_tip h0 == HS.get_tip h1)) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --initial_fuel 0 --initial_ifuel 0" (* Stack effect specific lemmas *) let lemma_stack_1 (#a:Type) (b:buffer a) h0 h1 h2 h3 : Lemma (requires (live h0 b /\ fresh_frame h0 h1 /\ modifies_1 b h1 h2 /\ popped h2 h3)) (ensures (modifies_buf_1 (frameOf b) b h0 h3)) [SMTPat (modifies_1 b h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () let lemma_stack_2 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 h3 : Lemma (requires (live h0 b /\ live h0 b' /\ fresh_frame h0 h1 /\ modifies_2 b b' h1 h2 /\ popped h2 h3)) (ensures (modifies_2 b b' h0 h3)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (fresh_frame h0 h1); SMTPat (popped h2 h3)] = () (* Specialized modifies clauses lemmas + associated SMTPatterns. Those are critical for // verification as the specialized modifies clauses are abstract from outside the // module *) (** Commutativity lemmas *) let lemma_modifies_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_2 b b' h0 h1 <==> modifies_2 b' b h0 h1)) [SMTPat (modifies_2 b b' h0 h1)] = () let lemma_modifies_3_2_comm (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 : Lemma (requires True) (ensures (modifies_3_2 b b' h0 h1 <==> modifies_3_2 b' b h0 h1)) [SMTPat (modifies_3_2 b b' h0 h1)] = () (* TODO: add commutativity lemmas for modifies_3 *) #reset-options "--z3rlimit 20" (** Transitivity lemmas *) let lemma_modifies_0_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_1 b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_2_1 b h0 h1 /\ modifies_2_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_2_1 b h1 h2)] = () let lemma_modifies_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) (* TODO: Make the following work and merge with the following lemma *) (* [SMTPatOr [ *) (* [SMTPat (modifies_2 b b' h0 h1); *) (* SMTPat (modifies_2 b' b h0 h1)]]; *) (* SMTPat (modifies_2 b' b h1 h2)] *) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_2 b b' h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () #reset-options "--z3rlimit 40" let lemma_modifies_3_trans (#a:Type) (#a':Type) (#a'':Type) (b:buffer a) (b':buffer a') (b'':buffer a'') h0 h1 h2 : Lemma (requires (modifies_3 b b' b'' h0 h1 /\ modifies_3 b b' b'' h1 h2)) (ensures (modifies_3 b b' b'' h0 h2)) (* TODO: add the appropriate SMTPatOr patterns so as not to rewrite X times the same lemma *) [SMTPat (modifies_3 b b' b'' h0 h1); SMTPat (modifies_3 b b' b'' h1 h2)] = () #reset-options "--z3rlimit 200" let lemma_modifies_3_2_trans (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b b' h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b b' h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () let lemma_modifies_3_2_trans' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (modifies_3_2 b' b h0 h1 /\ modifies_3_2 b b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_3_2 b' b h0 h1); SMTPat (modifies_3_2 b b' h1 h2)] = () #reset-options "--z3rlimit 20" (* Specific modifies clause lemmas *) val lemma_modifies_0_0: h0:mem -> h1:mem -> h2:mem -> Lemma (requires (modifies_0 h0 h1 /\ modifies_0 h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_0 h1 h2)] let lemma_modifies_0_0 h0 h1 h2 = () #reset-options "--z3rlimit 20 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_0 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ modifies_0 h1 h2)) (ensures (live h2 b /\ modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_0 h1 h2)] = () let lemma_modifies_0_1 (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_0_1' (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) [SMTPat (modifies_0 h0 h1); SMTPat (modifies_1 b h1 h2)] = () #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" let lemma_modifies_1_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_2 b b' h0 h2 /\ modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = if frameOf b = frameOf b' then modifies_trans_1_1' (frameOf b) b b' h0 h1 h2 else () #reset-options "--z3rlimit 200 --initial_fuel 0 --max_fuel 0" let lemma_modifies_0_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b b' h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_0_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ b' `unused_in` h0 /\ modifies_0 h0 h1 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_2 b' b h1 h2); SMTPat (modifies_0 h0 h1)] = () let lemma_modifies_1_2 (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_2 b' b h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_2'' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b b' h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b b' h1 h2)] = () let lemma_modifies_1_2''' (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_1 b h0 h1 /\ modifies_2 b' b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_2 b' b h1 h2)] = () let lemma_modifies_1_1_prime (#t:Type) (#t':Type) (b:buffer t) (b':buffer t') h0 h1 h2 : Lemma (requires (live h0 b /\ modifies_1 b h0 h1 /\ b' `unused_in` h0 /\ live h1 b' /\ modifies_1 b' h1 h2)) (ensures (modifies_2_1 b h0 h2)) [SMTPat (modifies_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () let lemma_modifies_2_1 (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b b' h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b b' h0 h2)) [SMTPat (modifies_2 b b' h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2 b' b h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_2 b' b h0 h2)) [SMTPat (modifies_2 b' b h0 h1); SMTPat (modifies_1 b h1 h2)] = () let lemma_modifies_2_1'' (#a:Type) (#a':Type) (b:buffer a) (b':buffer a') h0 h1 h2 : Lemma (requires (live h0 b /\ live h0 b' /\ modifies_2_1 b h0 h1 /\ modifies_1 b' h1 h2)) (ensures (modifies_3_2 b b' h0 h2)) [SMTPat (modifies_2_1 b h0 h1); SMTPat (modifies_1 b' h1 h2)] = () (* TODO: lemmas for modifies_3 *) let lemma_modifies_0_unalloc (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (b `unused_in` h0 /\ frameOf b == HS.get_tip h0 /\ modifies_0 h0 h1 /\ modifies_1 b h1 h2)) (ensures (modifies_0 h0 h2)) = () let lemma_modifies_none_1_trans (#a:Type) (b:buffer a) h0 h1 h2 : Lemma (requires (modifies_none h0 h1 /\ live h0 b /\ modifies_1 b h1 h2)) (ensures (modifies_1 b h0 h2)) = () let lemma_modifies_0_none_trans h0 h1 h2 : Lemma (requires (modifies_0 h0 h1 /\ modifies_none h1 h2)) (ensures (modifies_0 h0 h2)) = () #reset-options "--initial_fuel 0 --max_fuel 0" (** Concrete getters and setters *) val create: #a:Type -> init:a -> len:UInt32.t -> StackInline (buffer a) (requires (fun h -> True)) (ensures (fun (h0:mem) b h1 -> b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ frameOf b == HS.get_tip h0 /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.create (v len) init)) let create #a init len = let content: reference (lseq a (v len)) = salloc (Seq.create (v len) init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" unfold let p (#a:Type0) (init:list a) : GTot Type0 = normalize (0 < FStar.List.Tot.length init) /\ normalize (FStar.List.Tot.length init <= UInt.max_int 32) unfold let q (#a:Type0) (len:nat) (buf:buffer a) : GTot Type0 = normalize (length buf == len) (** Concrete getters and setters *) val createL: #a:Type0 -> init:list a -> StackInline (buffer a) (requires (fun h -> p #a init)) (ensures (fun (h0:mem) b h1 -> let len = FStar.List.Tot.length init in len > 0 /\ b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == len /\ frameOf b == (HS.get_tip h0) /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ modifies_0 h0 h1 /\ as_seq h1 b == Seq.seq_of_list init /\ q #a len b)) #set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded //whereas the L.length init below will not let createL #a init = let len = UInt32.uint_to_t (FStar.List.Tot.length init) in let s = Seq.seq_of_list init in let content: reference (lseq a (v len)) = salloc (Seq.seq_of_list init) in let b = MkBuffer len content 0ul len in let h = HST.get() in assert (Seq.equal (as_seq h b) (sel h b)); b #reset-options "--initial_fuel 0 --max_fuel 0" let lemma_upd (#a:Type) (h:mem) (x:reference a{live_region h (HS.frameOf x)}) (v:a) : Lemma (requires True) (ensures (Map.domain (HS.get_hmap h) == Map.domain (HS.get_hmap (upd h x v)))) = let m = HS.get_hmap h in let m' = Map.upd m (HS.frameOf x) (Heap.upd (Map.sel m (HS.frameOf x)) (HS.as_ref x) v) in Set.lemma_equal_intro (Map.domain m) (Map.domain m') unfold let rcreate_post_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (b:buffer a) (h0 h1:mem) :Type0 = b `unused_in` h0 /\ live h1 b /\ idx b == 0 /\ length b == v len /\ Map.domain (HS.get_hmap h1) == Map.domain (HS.get_hmap h0) /\ HS.get_tip h1 == HS.get_tip h0 /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r Set.empty h0 h1 /\ as_seq h1 b == Seq.create (v len) init private let rcreate_common (#a:Type) (r:rid) (init:a) (len:UInt32.t) (mm:bool) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm b.content == mm)) = let h0 = HST.get() in let s = Seq.create (v len) init in let content: reference (lseq a (v len)) = if mm then ralloc_mm r s else ralloc r s in let b = MkBuffer len content 0ul len in let h1 = HST.get() in assert (Seq.equal (as_seq h1 b) (sel h1 b)); lemma_upd h0 content s; b (** This function allocates a buffer in an "eternal" region, i.e. a region where memory is // * automatically-managed. One does not need to call rfree on such a buffer. It // * translates to C as a call to malloc and assumes a conservative garbage // * collector is running. *) val rcreate: #a:Type -> r:rid -> init:a -> len:UInt32.t -> ST (buffer a) (requires (fun h -> is_eternal_region r)) (ensures (fun (h0:mem) b h1 -> rcreate_post_common r init len b h0 h1 /\ ~(is_mm b.content))) let rcreate #a r init len = rcreate_common r init len false (** This predicate tells whether a buffer can be `rfree`d. The only way to produce it should be `rcreate_mm`, and the only way to consume it should be `rfree.` Rationale: a buffer can be `rfree`d only if it is the result of `rcreate_mm`. Subbuffers should not. *) let freeable (#a: Type) (b: buffer a) : GTot Type0 = is_mm b.content /\ is_eternal_region (frameOf b) /\ idx b == 0 (** This function allocates a buffer into a manually-managed buffer in a heap * region, meaning that the client must call rfree in order to avoid memory * leaks. It translates to C as a straight malloc. *) let rcreate_mm (#a:Type) (r:rid) (init:a) (len:UInt32.t) :ST (buffer a) (requires (fun h0 -> is_eternal_region r)) (ensures (fun h0 b h1 -> rcreate_post_common r init len b h0 h1 /\ is_mm (content b) /\ freeable b)) = rcreate_common r init len true #reset-options (** This function frees a buffer allocated with `rcreate_mm`. It translates to C as a regular free. *) let rfree (#a:Type) (b:buffer a) :ST unit (requires (fun h0 -> live h0 b /\ freeable b)) (ensures (fun h0 _ h1 -> is_mm (content b) /\ is_eternal_region (frameOf b) /\ h1 == HS.free (content b) h0)) = rfree b.content (* #reset-options "--z3rlimit 100 --initial_fuel 0 --max_fuel 0" *) (* val create_null: #a:Type -> init:a -> len:UInt32.t -> Stack (buffer a) *) (* (requires (fun h -> True)) *) (* (ensures (fun h0 b h1 -> length b = UInt32.v len /\ h0 == h1)) *) (* let create_null #a init len = *) (* push_frame(); *) (* let r = create init len in *) (* pop_frame(); *) (* r *) #reset-options "--initial_fuel 0 --max_fuel 0" // ocaml-only, used for conversions to Platform.bytes val to_seq: #a:Type -> b:buffer a -> l:UInt32.t{v l <= length b} -> STL (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ Seq.length r == v l (*/\ r == as_seq #a h1 b *) )) let to_seq #a b l = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v l) // ocaml-only, used for conversions to Platform.bytes val to_seq_full: #a:Type -> b:buffer a -> ST (seq a) (requires (fun h -> live h b)) (ensures (fun h0 r h1 -> h0 == h1 /\ live h1 b /\ r == as_seq #a h1 b )) let to_seq_full #a b = let s = !b.content in let i = v b.idx in Seq.slice s i (i + v b.length) val index: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> Stack a (requires (fun h -> live h b)) (ensures (fun h0 z h1 -> live h0 b /\ h1 == h0 /\ z == Seq.index (as_seq h0 b) (v n))) let index #a b n = let s = !b.content in Seq.index s (v b.idx + v n) (** REMARK: the proof of this lemma relies crucially on the `a == a'` condition // in `disjoint`, and on the pattern in `Seq.slice_upd` *) private let lemma_aux_0 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) (bb:buffer tt) :Lemma (requires (live h0 b /\ live h0 bb /\ disjoint b bb)) (ensures (live h0 b /\ live h0 bb /\ (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb))) = Heap.lemma_distinct_addrs_distinct_preorders (); Heap.lemma_distinct_addrs_distinct_mm () #set-options "--z3rlimit 10" private let lemma_aux_1 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) (tt:Type) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_0 b n z h0 tt)) #reset-options "--initial_fuel 0 --max_fuel 0" private let lemma_aux_2 (#a:Type) (b:buffer a) (n:UInt32.t{v n < length b}) (z:a) (h0:mem) :Lemma (requires (live h0 b)) (ensures (live h0 b /\ (forall (tt:Type) (bb:buffer tt). (live h0 bb /\ disjoint b bb) ==> (let h1 = HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z) in as_seq h0 bb == as_seq h1 bb)))) = let open FStar.Classical in forall_intro (move_requires (lemma_aux_1 b n z h0)) private val lemma_aux: #a:Type -> b:buffer a -> n:UInt32.t{v n < length b} -> z:a -> h0:mem -> Lemma (requires (live h0 b)) (ensures (live h0 b /\ modifies_1 b h0 (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z)) )) [SMTPat (HS.upd h0 b.content (Seq.upd (sel h0 b) (idx b + v n) z))] let lemma_aux #a b n z h0 = lemma_aux_2 b n z h0 val upd: #a:Type -> b:buffer a -> n:UInt32.t -> z:a -> Stack unit (requires (fun h -> live h b /\ v n < length b)) (ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ v n < length b /\ modifies_1 b h0 h1 /\ as_seq h1 b == Seq.upd (as_seq h0 b) (v n) z )) let upd #a b n z = let h0 = HST.get () in let s0 = !b.content in let s = Seq.upd s0 (v b.idx + v n) z in b.content := s; lemma_aux b n z h0; let h = HST.get() in Seq.lemma_eq_intro (as_seq h b) (Seq.slice s (idx b) (idx b + length b)); Seq.upd_slice s0 (idx b) (idx b + length b) (v n) z val sub: #a:Type -> b:buffer a -> i:UInt32.t -> len:UInt32.t{v i + v len <= length b} -> Tot (b':buffer a{b `includes` b' /\ length b' == v len}) let sub #a b i len = assert (v i + v b.idx < pow2 n); // was formerly a precondition MkBuffer b.max_length b.content (i +^ b.idx) len let sub_sub (#a: Type) (b: buffer a) (i1: UInt32.t) (len1: UInt32.t{v i1 + v len1 <= length b}) (i2: UInt32.t) (len2: UInt32.t {v i2 + v len2 <= v len1}) : Lemma (ensures (sub (sub b i1 len1) i2 len2 == sub b (i1 +^ i2) len2)) = () let sub_zero_length (#a: Type) (b: buffer a) : Lemma (ensures (sub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b)) = () let lemma_sub_spec (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (sub b i len); SMTPat (live h b)] = Seq.lemma_eq_intro (as_seq h (sub b i len)) (Seq.slice (as_seq h b) (v i) (v i + v len)) let lemma_sub_spec' (#a:Type) (b:buffer a) (i:UInt32.t) (len:UInt32.t{v len <= length b /\ v i + v len <= length b}) h : Lemma (requires (live h b)) (ensures (live h (sub b i len) /\ as_seq h (sub b i len) == Seq.slice (as_seq h b) (v i) (v i + v len))) [SMTPat (live h (sub b i len))] = lemma_sub_spec b i len h val offset: #a:Type -> b:buffer a -> i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length} -> Tot (b':buffer a{b `includes` b'}) let offset #a b i = MkBuffer b.max_length b.content (i +^ b.idx) (b.length -^ i) let lemma_offset_spec (#a:Type) (b:buffer a) (i:UInt32.t{v i + v b.idx < pow2 n /\ v i <= v b.length}) h : Lemma (requires True) (ensures (as_seq h (offset b i) == Seq.slice (as_seq h b) (v i) (length b))) [SMTPatOr [[SMTPat (as_seq h (offset b i))]; [SMTPat (Seq.slice (as_seq h b) (v i) (length b))]]] = Seq.lemma_eq_intro (as_seq h (offset b i)) (Seq.slice (as_seq h b) (v i) (length b)) private val eq_lemma1: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) (ensures equal h (sub b1 0ul len) h (sub b2 0ul len)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma1 #a b1 b2 len h = Seq.lemma_eq_intro (as_seq h (sub b1 0ul len)) (as_seq h (sub b2 0ul len)) #reset-options "--z3rlimit 20" private val eq_lemma2: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> h:mem -> Lemma (requires equal h (sub b1 0ul len) h (sub b2 0ul len)) (ensures (forall (j:nat). j < v len ==> get h b1 j == get h b2 j)) [SMTPat (equal h (sub b1 0ul len) h (sub b2 0ul len))] let eq_lemma2 #a b1 b2 len h = let s1 = as_seq h (sub b1 0ul len) in let s2 = as_seq h (sub b2 0ul len) in cut (forall (j:nat). j < v len ==> get h b1 j == Seq.index s1 j); cut (forall (j:nat). j < v len ==> get h b2 j == Seq.index s2 j) (** Corresponds to memcmp for `eqtype` *) val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
false
false
FStar.Buffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eqb: #a:eqtype -> b1:buffer a -> b2:buffer a -> len:UInt32.t{v len <= length b1 /\ v len <= length b2} -> ST bool (requires (fun h -> live h b1 /\ live h b2)) (ensures (fun h0 z h1 -> h1 == h0 /\ (z <==> equal h0 (sub b1 0ul len) h0 (sub b2 0ul len))))
[ "recursion" ]
FStar.Buffer.eqb
{ "file_name": "ulib/legacy/FStar.Buffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b1: FStar.Buffer.buffer a -> b2: FStar.Buffer.buffer a -> len: FStar.UInt32.t { FStar.UInt32.v len <= FStar.Buffer.length b1 /\ FStar.UInt32.v len <= FStar.Buffer.length b2 } -> FStar.HyperStack.ST.ST Prims.bool
{ "end_col": 11, "end_line": 1128, "start_col": 2, "start_line": 1122 }
Prims.Tot
val create5 (x0 x1 x2 x3 x4: uint64) : list uint64
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4]
val create5 (x0 x1 x2 x3 x4: uint64) : list uint64 let create5 (x0 x1 x2 x3 x4: uint64) : list uint64 =
false
null
false
[x0; x1; x2; x3; x4]
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Lib.IntTypes.uint64", "Prims.Cons", "Prims.Nil", "Prims.list" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create5 (x0 x1 x2 x3 x4: uint64) : list uint64
[]
Hacl.Spec.Ed25519.PrecompTable.create5
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x0: Lib.IntTypes.uint64 -> x1: Lib.IntTypes.uint64 -> x2: Lib.IntTypes.uint64 -> x3: Lib.IntTypes.uint64 -> x4: Lib.IntTypes.uint64 -> Prims.list Lib.IntTypes.uint64
{ "end_col": 72, "end_line": 17, "start_col": 52, "start_line": 17 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let felem_list = x:list uint64{FL.length x == 5}
let felem_list =
false
null
false
x: list uint64 {FL.length x == 5}
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Prims.list", "Lib.IntTypes.uint64", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4]
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val felem_list : Type0
[]
Hacl.Spec.Ed25519.PrecompTable.felem_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 48, "end_line": 20, "start_col": 17, "start_line": 20 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_list = x:list uint64{FL.length x == 20}
let point_list =
false
null
false
x: list uint64 {FL.length x == 20}
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Prims.list", "Lib.IntTypes.uint64", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5}
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_list : Type0
[]
Hacl.Spec.Ed25519.PrecompTable.point_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 49, "end_line": 22, "start_col": 17, "start_line": 22 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow51 = SF51.pow51
let pow51 =
false
null
false
SF51.pow51
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Hacl.Spec.Curve25519.Field51.Definition.pow51" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20}
false
false
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow51 : pow51: Prims.pos { Prims.pow2 64 == 8192 * pow51 /\ Prims.pow2 128 == (67108864 * pow51) * pow51 /\ pow51 == Prims.pow2 51 }
[]
Hacl.Spec.Ed25519.PrecompTable.pow51
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pow51: Prims.pos { Prims.pow2 64 == 8192 * pow51 /\ Prims.pow2 128 == (67108864 * pow51) * pow51 /\ pow51 == Prims.pow2 51 }
{ "end_col": 22, "end_line": 25, "start_col": 12, "start_line": 25 }
Prims.Tot
val ext_point_to_list (p: S.ext_point) : point_list
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ext_point_to_list (p:S.ext_point) : point_list = [@inline_let] let (px, py, pz, pt) = p in FL.(felem_to_list px @ felem_to_list py @ felem_to_list pz @ felem_to_list pt)
val ext_point_to_list (p: S.ext_point) : point_list let ext_point_to_list (p: S.ext_point) : point_list =
false
null
false
[@@ inline_let ]let px, py, pz, pt = p in let open FL in felem_to_list px @ felem_to_list py @ felem_to_list pz @ felem_to_list pt
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Spec.Ed25519.PointOps.ext_point", "Spec.Curve25519.elem", "FStar.List.Tot.Base.op_At", "Lib.IntTypes.uint64", "Hacl.Spec.Ed25519.PrecompTable.felem_to_list", "Hacl.Spec.Ed25519.PrecompTable.point_list" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102 [@"opaque_to_smt"] let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153 [@"opaque_to_smt"] let pow204: (pow204:pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) = let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204 inline_for_extraction noextract let felem_to_list (x:SC.elem) : felem_list = [@inline_let] let x0 = x % pow51 in [@inline_let] let x1 = x / pow51 % pow51 in [@inline_let] let x2 = x / pow102 % pow51 in [@inline_let] let x3 = x / pow153 % pow51 in [@inline_let] let x4 = x / pow204 in Math.Lemmas.lemma_div_lt_nat x 255 204; [@inline_let] let r = create5 (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4) in assert_norm (FL.length r = 5); r inline_for_extraction noextract
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ext_point_to_list (p: S.ext_point) : point_list
[]
Hacl.Spec.Ed25519.PrecompTable.ext_point_to_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Spec.Ed25519.PointOps.ext_point -> Hacl.Spec.Ed25519.PrecompTable.point_list
{ "end_col": 80, "end_line": 68, "start_col": 2, "start_line": 67 }
Prims.Tot
val pow102:(pow102: pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51})
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102
val pow102:(pow102: pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) let pow102:(pow102: pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) =
false
null
false
let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Prims.unit", "FStar.Math.Lemmas.pow2_plus", "FStar.Pervasives.normalize_term_spec", "Prims.pos", "Prims.pow2", "FStar.Pervasives.normalize_term" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51
false
false
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow102:(pow102: pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51})
[]
Hacl.Spec.Ed25519.PrecompTable.pow102
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pow102: Prims.pos { Prims.pow2 102 == pow102 /\ pow102 = Hacl.Spec.Ed25519.PrecompTable.pow51 * Hacl.Spec.Ed25519.PrecompTable.pow51 }
{ "end_col": 8, "end_line": 32, "start_col": 72, "start_line": 28 }
Prims.Tot
val pow153:(pow153: pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51})
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153
val pow153:(pow153: pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) let pow153:(pow153: pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) =
false
null
false
let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Prims.unit", "FStar.Math.Lemmas.pow2_plus", "FStar.Pervasives.normalize_term_spec", "Prims.pos", "Prims.pow2", "FStar.Pervasives.normalize_term" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102
false
false
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow153:(pow153: pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51})
[]
Hacl.Spec.Ed25519.PrecompTable.pow153
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pow153: Prims.pos { Prims.pow2 153 == pow153 /\ pow153 = (Hacl.Spec.Ed25519.PrecompTable.pow51 * Hacl.Spec.Ed25519.PrecompTable.pow51) * Hacl.Spec.Ed25519.PrecompTable.pow51 }
{ "end_col": 8, "end_line": 40, "start_col": 80, "start_line": 35 }
Prims.Tot
val pow204:(pow204: pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51})
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow204: (pow204:pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) = let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204
val pow204:(pow204: pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) let pow204:(pow204: pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) =
false
null
false
let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Prims.unit", "FStar.Math.Lemmas.pow2_plus", "FStar.Pervasives.normalize_term_spec", "Prims.pos", "Prims.pow2", "FStar.Pervasives.normalize_term" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102 [@"opaque_to_smt"] let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153
false
false
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow204:(pow204: pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51})
[]
Hacl.Spec.Ed25519.PrecompTable.pow204
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pow204: Prims.pos { Prims.pow2 204 == pow204 /\ pow204 = ((Hacl.Spec.Ed25519.PrecompTable.pow51 * Hacl.Spec.Ed25519.PrecompTable.pow51) * Hacl.Spec.Ed25519.PrecompTable.pow51) * Hacl.Spec.Ed25519.PrecompTable.pow51 }
{ "end_col": 8, "end_line": 49, "start_col": 88, "start_line": 43 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_inv_list (p:point_list) = let x = Seq.seq_of_list p <: lseq uint64 20 in //F51.inv_ext_point x F51.linv x
let point_inv_list (p: point_list) =
false
null
false
let x = Seq.seq_of_list p <: lseq uint64 20 in F51.linv x
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Hacl.Spec.Ed25519.PrecompTable.point_list", "Hacl.Impl.Ed25519.Field51.linv", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Seq.Properties.seq_of_list", "Lib.IntTypes.uint64" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102 [@"opaque_to_smt"] let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153 [@"opaque_to_smt"] let pow204: (pow204:pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) = let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204 inline_for_extraction noextract let felem_to_list (x:SC.elem) : felem_list = [@inline_let] let x0 = x % pow51 in [@inline_let] let x1 = x / pow51 % pow51 in [@inline_let] let x2 = x / pow102 % pow51 in [@inline_let] let x3 = x / pow153 % pow51 in [@inline_let] let x4 = x / pow204 in Math.Lemmas.lemma_div_lt_nat x 255 204; [@inline_let] let r = create5 (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4) in assert_norm (FL.length r = 5); r inline_for_extraction noextract let ext_point_to_list (p:S.ext_point) : point_list = [@inline_let] let (px, py, pz, pt) = p in FL.(felem_to_list px @ felem_to_list py @ felem_to_list pz @ felem_to_list pt)
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_inv_list : p: Hacl.Spec.Ed25519.PrecompTable.point_list -> Type0
[]
Hacl.Spec.Ed25519.PrecompTable.point_inv_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Hacl.Spec.Ed25519.PrecompTable.point_list -> Type0
{ "end_col": 12, "end_line": 75, "start_col": 35, "start_line": 72 }
Prims.GTot
val point_eval_list (p: point_list) : GTot S.ext_point
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_eval_list (p:point_list) : GTot S.ext_point = let x = Seq.seq_of_list p <: lseq uint64 20 in F51.refl_ext_point x
val point_eval_list (p: point_list) : GTot S.ext_point let point_eval_list (p: point_list) : GTot S.ext_point =
false
null
false
let x = Seq.seq_of_list p <: lseq uint64 20 in F51.refl_ext_point x
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "sometrivial" ]
[ "Hacl.Spec.Ed25519.PrecompTable.point_list", "Hacl.Impl.Ed25519.Field51.refl_ext_point", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Seq.Properties.seq_of_list", "Lib.IntTypes.uint64", "Spec.Ed25519.PointOps.ext_point" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102 [@"opaque_to_smt"] let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153 [@"opaque_to_smt"] let pow204: (pow204:pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) = let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204 inline_for_extraction noextract let felem_to_list (x:SC.elem) : felem_list = [@inline_let] let x0 = x % pow51 in [@inline_let] let x1 = x / pow51 % pow51 in [@inline_let] let x2 = x / pow102 % pow51 in [@inline_let] let x3 = x / pow153 % pow51 in [@inline_let] let x4 = x / pow204 in Math.Lemmas.lemma_div_lt_nat x 255 204; [@inline_let] let r = create5 (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4) in assert_norm (FL.length r = 5); r inline_for_extraction noextract let ext_point_to_list (p:S.ext_point) : point_list = [@inline_let] let (px, py, pz, pt) = p in FL.(felem_to_list px @ felem_to_list py @ felem_to_list pz @ felem_to_list pt) inline_for_extraction noextract let point_inv_list (p:point_list) = let x = Seq.seq_of_list p <: lseq uint64 20 in //F51.inv_ext_point x F51.linv x
false
false
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_eval_list (p: point_list) : GTot S.ext_point
[]
Hacl.Spec.Ed25519.PrecompTable.point_eval_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Hacl.Spec.Ed25519.PrecompTable.point_list -> Prims.GTot Spec.Ed25519.PointOps.ext_point
{ "end_col": 22, "end_line": 80, "start_col": 55, "start_line": 78 }
Prims.Tot
val felem_to_list (x: SC.elem) : felem_list
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FL" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "SF51" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let felem_to_list (x:SC.elem) : felem_list = [@inline_let] let x0 = x % pow51 in [@inline_let] let x1 = x / pow51 % pow51 in [@inline_let] let x2 = x / pow102 % pow51 in [@inline_let] let x3 = x / pow153 % pow51 in [@inline_let] let x4 = x / pow204 in Math.Lemmas.lemma_div_lt_nat x 255 204; [@inline_let] let r = create5 (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4) in assert_norm (FL.length r = 5); r
val felem_to_list (x: SC.elem) : felem_list let felem_to_list (x: SC.elem) : felem_list =
false
null
false
[@@ inline_let ]let x0 = x % pow51 in [@@ inline_let ]let x1 = x / pow51 % pow51 in [@@ inline_let ]let x2 = x / pow102 % pow51 in [@@ inline_let ]let x3 = x / pow153 % pow51 in [@@ inline_let ]let x4 = x / pow204 in Math.Lemmas.lemma_div_lt_nat x 255 204; [@@ inline_let ]let r = create5 (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4) in assert_norm (FL.length r = 5); r
{ "checked_file": "Hacl.Spec.Ed25519.PrecompTable.fsti.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Ed25519.PrecompTable.fsti" }
[ "total" ]
[ "Spec.Curve25519.elem", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Lib.IntTypes.uint64", "Prims.list", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Ed25519.PrecompTable.create5", "Lib.IntTypes.u64", "FStar.Math.Lemmas.lemma_div_lt_nat", "Prims.op_Division", "Hacl.Spec.Ed25519.PrecompTable.pow204", "Prims.op_Modulus", "Hacl.Spec.Ed25519.PrecompTable.pow153", "Hacl.Spec.Ed25519.PrecompTable.pow51", "Hacl.Spec.Ed25519.PrecompTable.pow102", "Hacl.Spec.Ed25519.PrecompTable.felem_list" ]
[]
module Hacl.Spec.Ed25519.PrecompTable open FStar.Mul open Lib.IntTypes open Lib.Sequence module F51 = Hacl.Impl.Ed25519.Field51 module SF51 = Hacl.Spec.Curve25519.Field51.Definition module S = Spec.Ed25519 module SC = Spec.Curve25519 module FL = FStar.List.Tot #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let create5 (x0 x1 x2 x3 x4:uint64) : list uint64 = [x0; x1; x2; x3; x4] inline_for_extraction noextract let felem_list = x:list uint64{FL.length x == 5} inline_for_extraction noextract let point_list = x:list uint64{FL.length x == 20} inline_for_extraction noextract let pow51 = SF51.pow51 [@"opaque_to_smt"] let pow102: (pow102:pos{pow2 102 == pow102 /\ pow102 = pow51 * pow51}) = let pow102:pos = normalize_term (pow2 102) in normalize_term_spec (pow2 102); Math.Lemmas.pow2_plus 51 51; pow102 [@"opaque_to_smt"] let pow153: (pow153:pos{pow2 153 == pow153 /\ pow153 = pow51 * pow51 * pow51}) = let pow153:pos = normalize_term (pow2 153) in normalize_term_spec (pow2 153); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; pow153 [@"opaque_to_smt"] let pow204: (pow204:pos{pow2 204 == pow204 /\ pow204 = pow51 * pow51 * pow51 * pow51}) = let pow204:pos = normalize_term (pow2 204) in normalize_term_spec (pow2 204); Math.Lemmas.pow2_plus 51 51; Math.Lemmas.pow2_plus 102 51; Math.Lemmas.pow2_plus 153 51; pow204 inline_for_extraction noextract
false
true
Hacl.Spec.Ed25519.PrecompTable.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val felem_to_list (x: SC.elem) : felem_list
[]
Hacl.Spec.Ed25519.PrecompTable.felem_to_list
{ "file_name": "code/ed25519/Hacl.Spec.Ed25519.PrecompTable.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Spec.Curve25519.elem -> Hacl.Spec.Ed25519.PrecompTable.felem_list
{ "end_col": 3, "end_line": 62, "start_col": 2, "start_line": 54 }
Prims.Tot
val point_mul_g (a: qelem) : proj_point
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_mul_g (a:qelem) : proj_point = point_mul a base_point
val point_mul_g (a: qelem) : proj_point let point_mul_g (a: qelem) : proj_point =
false
null
false
point_mul a base_point
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.qelem", "Spec.P256.point_mul", "Spec.P256.PointOps.base_point", "Spec.P256.PointOps.proj_point" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_mul_g (a: qelem) : proj_point
[]
Spec.P256.point_mul_g
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.proj_point
{ "end_col": 63, "end_line": 63, "start_col": 41, "start_line": 63 }
Prims.Tot
val point_mul (a: qelem) (p: proj_point) : proj_point
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4
val point_mul (a: qelem) (p: proj_point) : proj_point let point_mul (a: qelem) (p: proj_point) : proj_point =
false
null
false
SE.exp_fw mk_p256_concrete_ops p 256 a 4
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.proj_point", "Spec.Exponentiation.exp_fw", "Spec.P256.mk_p256_concrete_ops" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_mul (a: qelem) (p: proj_point) : proj_point
[]
Spec.P256.point_mul
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.P256.PointOps.qelem -> p: Spec.P256.PointOps.proj_point -> Spec.P256.PointOps.proj_point
{ "end_col": 42, "end_line": 60, "start_col": 2, "start_line": 60 }
Prims.Tot
val point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
val point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point let point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point =
false
null
false
SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.proj_point", "Spec.Exponentiation.exp_double_fw", "Spec.P256.mk_p256_concrete_ops", "Spec.P256.PointOps.base_point" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_mul_double_g (a1 a2: qelem) (p: proj_point) : proj_point
[]
Spec.P256.point_mul_double_g
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a1: Spec.P256.PointOps.qelem -> a2: Spec.P256.PointOps.qelem -> p: Spec.P256.PointOps.proj_point -> Spec.P256.PointOps.proj_point
{ "end_col": 64, "end_line": 67, "start_col": 2, "start_line": 67 }
Prims.Tot
val mk_p256_comm_monoid:LE.comm_monoid aff_point
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; }
val mk_p256_comm_monoid:LE.comm_monoid aff_point let mk_p256_comm_monoid:LE.comm_monoid aff_point =
false
null
false
{ LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma }
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.Exponentiation.Definition.Mkcomm_monoid", "Spec.P256.PointOps.aff_point", "Spec.P256.PointOps.aff_point_at_inf", "Spec.P256.PointOps.aff_point_add", "Spec.P256.Lemmas.aff_point_at_inf_lemma", "Spec.P256.Lemmas.aff_point_add_assoc_lemma", "Spec.P256.Lemmas.aff_point_add_comm_lemma" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_p256_comm_monoid:LE.comm_monoid aff_point
[]
Spec.P256.mk_p256_comm_monoid
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Lib.Exponentiation.Definition.comm_monoid Spec.P256.PointOps.aff_point
{ "end_col": 50, "end_line": 27, "start_col": 2, "start_line": 23 }
Prims.Tot
val min_input_length (a: hash_alg_ecdsa) : nat
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0
val min_input_length (a: hash_alg_ecdsa) : nat let min_input_length (a: hash_alg_ecdsa) : nat =
false
null
false
match a with | NoHash -> 32 | Hash a -> 0
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.hash_alg_ecdsa", "Spec.Hash.Definitions.hash_alg", "Prims.l_or", "Prims.eq2", "Spec.Hash.Definitions.SHA2_256", "Spec.Hash.Definitions.SHA2_384", "Spec.Hash.Definitions.SHA2_512", "Prims.nat" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val min_input_length (a: hash_alg_ecdsa) : nat
[]
Spec.P256.min_input_length
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.P256.hash_alg_ecdsa -> Prims.nat
{ "end_col": 43, "end_line": 84, "start_col": 2, "start_line": 84 }
Prims.Tot
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double_c p = PL.to_aff_point_double_lemma p; point_double p
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p =
false
null
false
PL.to_aff_point_double_lemma p; point_double p
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.proj_point", "Spec.P256.PointOps.point_double", "Prims.unit", "Spec.P256.Lemmas.to_aff_point_double_lemma" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid
[]
Spec.P256.point_double_c
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Spec.Exponentiation.sqr_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid
{ "end_col": 16, "end_line": 49, "start_col": 2, "start_line": 48 }
Prims.Tot
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q =
false
null
false
PL.to_aff_point_add_lemma p q; point_add p q
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.proj_point", "Spec.P256.PointOps.point_add", "Prims.unit", "Spec.P256.Lemmas.to_aff_point_add_lemma" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid
[]
Spec.P256.point_add_c
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Spec.Exponentiation.mul_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid
{ "end_col": 15, "end_line": 44, "start_col": 2, "start_line": 43 }
Prims.Tot
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ =
false
null
false
PL.to_aff_point_at_infinity_lemma (); point_at_inf
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Prims.unit", "Spec.P256.PointOps.point_at_inf", "Spec.P256.Lemmas.to_aff_point_at_infinity_lemma", "Spec.P256.PointOps.proj_point" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
false
true
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid
[]
Spec.P256.point_at_inf_c
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Spec.Exponentiation.one_st Spec.P256.PointOps.proj_point Spec.P256.mk_to_p256_comm_monoid
{ "end_col": 14, "end_line": 39, "start_col": 2, "start_line": 38 }
Prims.Tot
val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg =
false
null
false
match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.hash_alg_ecdsa", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Spec.P256.min_input_length", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.Hash.Definitions.hash_alg", "Prims.l_or", "Prims.eq2", "Spec.Hash.Definitions.SHA2_256", "Spec.Hash.Definitions.SHA2_384", "Spec.Hash.Definitions.SHA2_512", "Spec.Agile.Hash.hash", "Lib.ByteSequence.lbytes", "Spec.P256.uu___is_Hash", "Spec.Hash.Definitions.hash_length", "Prims.op_Negation", "Spec.Hash.Definitions.is_shake", "Prims.bool", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32})
[]
Spec.P256.hash_ecdsa
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.P256.hash_alg_ecdsa -> msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length a} -> msg: Lib.Sequence.lseq Lib.IntTypes.uint8 msg_len -> r: Lib.ByteSequence.lbytes (match Hash? a with | true -> Spec.Hash.Definitions.hash_length (let Spec.P256.Hash a = a in a) | _ -> msg_len) {Lib.Sequence.length r >= 32}
{ "end_col": 69, "end_line": 95, "start_col": 2, "start_line": 95 }
Prims.Tot
val validate_public_key (pk: lbytes 64) : bool
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let validate_public_key (pk:lbytes 64) : bool = Some? (load_point pk)
val validate_public_key (pk: lbytes 64) : bool let validate_public_key (pk: lbytes 64) : bool =
false
null
false
Some? (load_point pk)
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "FStar.Pervasives.Native.uu___is_Some", "Spec.P256.PointOps.proj_point", "Spec.P256.PointOps.load_point", "Prims.bool" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None /// Parsing and Serializing public keys // raw = [ x; y ], 64 bytes // uncompressed = [ 0x04; x; y ], 65 bytes // compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_public_key (pk: lbytes 64) : bool
[]
Spec.P256.validate_public_key
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pk: Lib.ByteSequence.lbytes 64 -> Prims.bool
{ "end_col": 23, "end_line": 202, "start_col": 2, "start_line": 202 }
Prims.Tot
val ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end
val ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool let ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool =
false
null
false
let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else let x = _X /% _Z in x % order = r
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.qelem", "Lib.ByteSequence.lbytes", "Prims.op_Negation", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some", "Spec.P256.PointOps.proj_point", "Prims.bool", "Prims.nat", "Spec.P256.PointOps.is_point_at_inf", "FStar.Pervasives.Native.Mktuple3", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Spec.P256.PointOps.order", "Spec.P256.PointOps.felem", "Spec.P256.PointOps.op_Slash_Percent", "Spec.P256.point_mul_double_g", "FStar.Pervasives.Native.__proj__Some__item__v", "Spec.P256.PointOps.op_Star_Hat", "Spec.P256.PointOps.qinv", "Prims.op_LessThan", "Prims.b2t", "Prims.pow2", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.ByteSequence.nat_from_bytes_be", "FStar.Pervasives.Native.option", "Spec.P256.PointOps.load_point" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ecdsa_verify_msg_as_qelem (m: qelem) (public_key: lbytes 64) (sign_r sign_s: lbytes 32) : bool
[]
Spec.P256.ecdsa_verify_msg_as_qelem
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Spec.P256.PointOps.qelem -> public_key: Lib.ByteSequence.lbytes 64 -> sign_r: Lib.ByteSequence.lbytes 32 -> sign_s: Lib.ByteSequence.lbytes 32 -> Prims.bool
{ "end_col": 5, "end_line": 134, "start_col": 97, "start_line": 117 }
Prims.Tot
val secret_to_public (private_key: lbytes 32) : option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None
val secret_to_public (private_key: lbytes 32) : option (lbytes 64) let secret_to_public (private_key: lbytes 32) : option (lbytes 64) =
false
null
false
let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "FStar.Pervasives.Native.Some", "Spec.P256.PointOps.point_store", "Spec.P256.PointOps.proj_point", "Spec.P256.point_mul_g", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.op_AmpAmp", "Prims.op_LessThan", "Spec.P256.PointOps.order", "Prims.nat", "Prims.b2t", "Prims.pow2", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.ByteSequence.nat_from_bytes_be" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val secret_to_public (private_key: lbytes 32) : option (lbytes 64)
[]
Spec.P256.secret_to_public
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
private_key: Lib.ByteSequence.lbytes 32 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 11, "end_line": 182, "start_col": 67, "start_line": 176 }
Prims.Tot
val ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None
val ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64) let ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64) =
false
null
false
let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some", "Spec.P256.PointOps.proj_point", "FStar.Pervasives.Native.Some", "Spec.P256.PointOps.point_store", "Spec.P256.point_mul", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.op_LessThan", "Spec.P256.PointOps.order", "Prims.nat", "Prims.b2t", "Prims.pow2", "Prims.op_Multiply", "Lib.Sequence.length", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.ByteSequence.nat_from_bytes_be", "Spec.P256.PointOps.load_point" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ecdh (their_public_key: lbytes 64) (private_key: lbytes 32) : option (lbytes 64)
[]
Spec.P256.ecdh
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
their_public_key: Lib.ByteSequence.lbytes 64 -> private_key: Lib.ByteSequence.lbytes 32 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 11, "end_line": 192, "start_col": 84, "start_line": 185 }
Prims.Tot
val pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 = concat (create 1 (u8 0x04)) pk
val pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65 let pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65 =
false
null
false
concat (create 1 (u8 0x04)) pk
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "Lib.Sequence.concat", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.create", "Lib.IntTypes.u8" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None /// Parsing and Serializing public keys // raw = [ x; y ], 64 bytes // uncompressed = [ 0x04; x; y ], 65 bytes // compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes let validate_public_key (pk:lbytes 64) : bool = Some? (load_point pk) let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) = if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64)
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pk_uncompressed_from_raw (pk: lbytes 64) : lbytes 65
[]
Spec.P256.pk_uncompressed_from_raw
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pk: Lib.ByteSequence.lbytes 64 -> Lib.ByteSequence.lbytes 65
{ "end_col": 32, "end_line": 208, "start_col": 2, "start_line": 208 }
Prims.Tot
val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s =
false
null
false
let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.hash_alg_ecdsa", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Spec.P256.min_input_length", "Lib.ByteSequence.lbytes", "Spec.P256.ecdsa_verify_msg_as_qelem", "Prims.int", "Prims.op_Modulus", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.SEC", "Lib.Sequence.sub", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Spec.P256.uu___is_Hash", "Spec.Hash.Definitions.hash_length", "Spec.Hash.Definitions.hash_alg", "Prims.l_or", "Prims.eq2", "Spec.Hash.Definitions.SHA2_256", "Spec.Hash.Definitions.SHA2_384", "Spec.Hash.Definitions.SHA2_512", "Prims.op_Negation", "Spec.Hash.Definitions.is_shake", "Prims.bool", "Spec.P256.PointOps.order", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.Sequence.length", "Spec.P256.hash_ecdsa" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool
[]
Spec.P256.ecdsa_verification_agile
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Spec.P256.hash_alg_ecdsa -> msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length alg} -> msg: Lib.ByteSequence.lbytes msg_len -> public_key: Lib.ByteSequence.lbytes 64 -> signature_r: Lib.ByteSequence.lbytes 32 -> signature_s: Lib.ByteSequence.lbytes 32 -> Prims.bool
{ "end_col": 66, "end_line": 171, "start_col": 81, "start_line": 168 }
Prims.Tot
val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce
val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce =
false
null
false
let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.hash_alg_ecdsa", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Spec.P256.min_input_length", "Lib.ByteSequence.lbytes", "Spec.P256.ecdsa_sign_msg_as_qelem", "Prims.int", "Prims.op_Modulus", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.SEC", "Lib.Sequence.sub", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Spec.P256.uu___is_Hash", "Spec.Hash.Definitions.hash_length", "Spec.Hash.Definitions.hash_alg", "Prims.l_or", "Prims.eq2", "Spec.Hash.Definitions.SHA2_256", "Spec.Hash.Definitions.SHA2_384", "Spec.Hash.Definitions.SHA2_512", "Prims.op_Negation", "Spec.Hash.Definitions.is_shake", "Prims.bool", "Spec.P256.PointOps.order", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.Sequence.length", "Spec.P256.hash_ecdsa", "FStar.Pervasives.Native.option" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64)
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64)
[]
Spec.P256.ecdsa_signature_agile
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Spec.P256.hash_alg_ecdsa -> msg_len: Lib.IntTypes.size_nat{msg_len >= Spec.P256.min_input_length alg} -> msg: Lib.ByteSequence.lbytes msg_len -> private_key: Lib.ByteSequence.lbytes 32 -> nonce: Lib.ByteSequence.lbytes 32 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 47, "end_line": 156, "start_col": 61, "start_line": 153 }
Prims.Tot
val pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pk_compressed_to_raw (pk:lbytes 33) : option (lbytes 64) = let pk_x = sub pk 1 32 in match (aff_point_decompress pk) with | Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y)) | None -> None
val pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64) let pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64) =
false
null
false
let pk_x = sub pk 1 32 in match (aff_point_decompress pk) with | Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y)) | None -> None
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "Spec.P256.PointOps.aff_point_decompress", "Prims.nat", "FStar.Pervasives.Native.Some", "Lib.Sequence.concat", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.ByteSequence.nat_to_bytes_be", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.l_Forall", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.sub" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None /// Parsing and Serializing public keys // raw = [ x; y ], 64 bytes // uncompressed = [ 0x04; x; y ], 65 bytes // compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes let validate_public_key (pk:lbytes 64) : bool = Some? (load_point pk) let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) = if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64) let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 = concat (create 1 (u8 0x04)) pk
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pk_compressed_to_raw (pk: lbytes 33) : option (lbytes 64)
[]
Spec.P256.pk_compressed_to_raw
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pk: Lib.ByteSequence.lbytes 33 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 16, "end_line": 214, "start_col": 62, "start_line": 210 }
Prims.Tot
val pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) = if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64)
val pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64) let pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64) =
false
null
false
if Lib.RawIntTypes.u8_to_UInt8 pk.[ 0 ] <> 0x04uy then None else Some (sub pk 1 64)
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "Prims.op_disEquality", "FStar.UInt8.t", "Lib.RawIntTypes.u8_to_UInt8", "Lib.Sequence.op_String_Access", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt8.__uint_to_t", "FStar.Pervasives.Native.None", "Prims.bool", "FStar.Pervasives.Native.Some", "Lib.Sequence.sub", "FStar.Pervasives.Native.option" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None /// Parsing and Serializing public keys // raw = [ x; y ], 64 bytes // uncompressed = [ 0x04; x; y ], 65 bytes // compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes let validate_public_key (pk:lbytes 64) : bool = Some? (load_point pk)
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pk_uncompressed_to_raw (pk: lbytes 65) : option (lbytes 64)
[]
Spec.P256.pk_uncompressed_to_raw
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pk: Lib.ByteSequence.lbytes 65 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 83, "end_line": 205, "start_col": 2, "start_line": 205 }
Prims.Tot
val ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64)
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end
val ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64) let ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64) =
false
null
false
let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb)
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Spec.P256.PointOps.qelem", "Lib.ByteSequence.lbytes", "Prims.op_Negation", "Prims.op_AmpAmp", "FStar.Pervasives.Native.None", "Prims.bool", "Prims.nat", "Prims.op_BarBar", "Prims.op_Equality", "Prims.int", "FStar.Pervasives.Native.Some", "Lib.Sequence.concat", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.Pervasives.Native.option", "Lib.Sequence.seq", "Lib.IntTypes.int_t", "Prims.l_and", "Prims.eq2", "Lib.Sequence.length", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "Lib.ByteSequence.nat_from_intseq_be", "Lib.ByteSequence.nat_to_bytes_be", "Spec.P256.PointOps.op_Star_Hat", "Spec.P256.PointOps.op_Plus_Hat", "Spec.P256.PointOps.qinv", "Prims.op_Modulus", "Spec.P256.PointOps.order", "Spec.P256.PointOps.felem", "Spec.P256.PointOps.op_Slash_Percent", "Spec.P256.PointOps.proj_point", "Spec.P256.point_mul_g", "Lib.ByteSequence.nat_from_bytes_be" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ecdsa_sign_msg_as_qelem (m: qelem) (private_key nonce: lbytes 32) : option (lbytes 64)
[]
Spec.P256.ecdsa_sign_msg_as_qelem
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Spec.P256.PointOps.qelem -> private_key: Lib.ByteSequence.lbytes 32 -> nonce: Lib.ByteSequence.lbytes 32 -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes 64)
{ "end_col": 71, "end_line": 114, "start_col": 90, "start_line": 98 }
Prims.Tot
val pk_compressed_from_raw (pk: lbytes 64) : lbytes 33
[ { "abbrev": false, "full_module": "Spec.P256.PointOps", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pk_compressed_from_raw (pk:lbytes 64) : lbytes 33 = let pk_x = sub pk 0 32 in let pk_y = sub pk 32 32 in let is_pk_y_odd = nat_from_bytes_be pk_y % 2 = 1 in // <==> pk_y % 2 = 1 let pk0 = if is_pk_y_odd then u8 0x03 else u8 0x02 in concat (create 1 pk0) pk_x
val pk_compressed_from_raw (pk: lbytes 64) : lbytes 33 let pk_compressed_from_raw (pk: lbytes 64) : lbytes 33 =
false
null
false
let pk_x = sub pk 0 32 in let pk_y = sub pk 32 32 in let is_pk_y_odd = nat_from_bytes_be pk_y % 2 = 1 in let pk0 = if is_pk_y_odd then u8 0x03 else u8 0x02 in concat (create 1 pk0) pk_x
{ "checked_file": "Spec.P256.fst.checked", "dependencies": [ "Spec.P256.PointOps.fst.checked", "Spec.P256.Lemmas.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Exponentiation.fsti.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Spec.P256.fst" }
[ "total" ]
[ "Lib.ByteSequence.lbytes", "Lib.Sequence.concat", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.create", "Lib.IntTypes.int_t", "Lib.IntTypes.u8", "Prims.bool", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.ByteSequence.nat_from_bytes_be", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.sub" ]
[]
module Spec.P256 open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Hash.Definitions module M = Lib.NatMod module LE = Lib.Exponentiation module SE = Spec.Exponentiation module PL = Spec.P256.Lemmas include Spec.P256.PointOps #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** https://eprint.iacr.org/2013/816.pdf *) /// Elliptic curve scalar multiplication let mk_p256_comm_monoid : LE.comm_monoid aff_point = { LE.one = aff_point_at_inf; LE.mul = aff_point_add; LE.lemma_one = PL.aff_point_at_inf_lemma; LE.lemma_mul_assoc = PL.aff_point_add_assoc_lemma; LE.lemma_mul_comm = PL.aff_point_add_comm_lemma; } let mk_to_p256_comm_monoid : SE.to_comm_monoid proj_point = { SE.a_spec = aff_point; SE.comm_monoid = mk_p256_comm_monoid; SE.refl = to_aff_point; } val point_at_inf_c: SE.one_st proj_point mk_to_p256_comm_monoid let point_at_inf_c _ = PL.to_aff_point_at_infinity_lemma (); point_at_inf val point_add_c : SE.mul_st proj_point mk_to_p256_comm_monoid let point_add_c p q = PL.to_aff_point_add_lemma p q; point_add p q val point_double_c : SE.sqr_st proj_point mk_to_p256_comm_monoid let point_double_c p = PL.to_aff_point_double_lemma p; point_double p let mk_p256_concrete_ops : SE.concrete_ops proj_point = { SE.to = mk_to_p256_comm_monoid; SE.one = point_at_inf_c; SE.mul = point_add_c; SE.sqr = point_double_c; } // [a]P let point_mul (a:qelem) (p:proj_point) : proj_point = SE.exp_fw mk_p256_concrete_ops p 256 a 4 // [a]G let point_mul_g (a:qelem) : proj_point = point_mul a base_point // [a1]G + [a2]P let point_mul_double_g (a1 a2:qelem) (p:proj_point) : proj_point = SE.exp_double_fw mk_p256_concrete_ops base_point 256 a1 p a2 5 /// ECDSA over the P256 elliptic curve type hash_alg_ecdsa = | NoHash | Hash of (a:hash_alg{a == SHA2_256 \/ a == SHA2_384 \/ a == SHA2_512}) let _: squash (inversion hash_alg_ecdsa) = allow_inversion hash_alg_ecdsa let _: squash (pow2 32 < pow2 61 /\ pow2 32 < pow2 125) = Math.Lemmas.pow2_lt_compat 61 32; Math.Lemmas.pow2_lt_compat 125 32 let min_input_length (a:hash_alg_ecdsa) : nat = match a with | NoHash -> 32 | Hash a -> 0 val hash_ecdsa: a:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length a} -> msg:lseq uint8 msg_len -> Tot (r:lbytes (if Hash? a then hash_length (match a with Hash a -> a) else msg_len){length r >= 32}) let hash_ecdsa a msg_len msg = match a with | NoHash -> msg | Hash a -> Spec.Agile.Hash.hash a msg let ecdsa_sign_msg_as_qelem (m:qelem) (private_key nonce:lbytes 32) : option (lbytes 64) = let k_q = nat_from_bytes_be nonce in let d_a = nat_from_bytes_be private_key in let is_privkey_valid = 0 < d_a && d_a < order in let is_nonce_valid = 0 < k_q && k_q < order in if not (is_privkey_valid && is_nonce_valid) then None else begin let _X, _Y, _Z = point_mul_g k_q in let x = _X /% _Z in let r = x % order in let kinv = qinv k_q in let s = kinv *^ (m +^ r *^ d_a) in let rb = nat_to_bytes_be 32 r in let sb = nat_to_bytes_be 32 s in if r = 0 || s = 0 then None else Some (concat #_ #32 #32 rb sb) end let ecdsa_verify_msg_as_qelem (m:qelem) (public_key:lbytes 64) (sign_r sign_s:lbytes 32) : bool = let pk = load_point public_key in let r = nat_from_bytes_be sign_r in let s = nat_from_bytes_be sign_s in let is_r_valid = 0 < r && r < order in let is_s_valid = 0 < s && s < order in if not (Some? pk && is_r_valid && is_s_valid) then false else begin let sinv = qinv s in let u1 = sinv *^ m in let u2 = sinv *^ r in let _X, _Y, _Z = point_mul_double_g u1 u2 (Some?.v pk) in if is_point_at_inf (_X, _Y, _Z) then false else begin let x = _X /% _Z in x % order = r end end (* _Z <> 0 q < prime < 2 * q let x = _X /% _Z in x % q = r <==> 1. x = r <==> _X = r *% _Z 2. x - q = r <==> _X = (r + q) *% _Z *) val ecdsa_signature_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> private_key:lbytes 32 -> nonce:lbytes 32 -> option (lbytes 64) let ecdsa_signature_agile alg msg_len msg private_key nonce = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_sign_msg_as_qelem m_q private_key nonce val ecdsa_verification_agile: alg:hash_alg_ecdsa -> msg_len:size_nat{msg_len >= min_input_length alg} -> msg:lbytes msg_len -> public_key:lbytes 64 -> signature_r:lbytes 32 -> signature_s:lbytes 32 -> bool let ecdsa_verification_agile alg msg_len msg public_key signature_r signature_s = let hashM = hash_ecdsa alg msg_len msg in let m_q = nat_from_bytes_be (sub hashM 0 32) % order in ecdsa_verify_msg_as_qelem m_q public_key signature_r signature_s /// ECDH over the P256 elliptic curve let secret_to_public (private_key:lbytes 32) : option (lbytes 64) = let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if is_sk_valid then let pk = point_mul_g sk in Some (point_store pk) else None let ecdh (their_public_key:lbytes 64) (private_key:lbytes 32) : option (lbytes 64) = let pk = load_point their_public_key in let sk = nat_from_bytes_be private_key in let is_sk_valid = 0 < sk && sk < order in if Some? pk && is_sk_valid then let ss = point_mul sk (Some?.v pk) in Some (point_store ss) else None /// Parsing and Serializing public keys // raw = [ x; y ], 64 bytes // uncompressed = [ 0x04; x; y ], 65 bytes // compressed = [ 0x02 for even `y` and 0x03 for odd `y`; x ], 33 bytes let validate_public_key (pk:lbytes 64) : bool = Some? (load_point pk) let pk_uncompressed_to_raw (pk:lbytes 65) : option (lbytes 64) = if Lib.RawIntTypes.u8_to_UInt8 pk.[0] <> 0x04uy then None else Some (sub pk 1 64) let pk_uncompressed_from_raw (pk:lbytes 64) : lbytes 65 = concat (create 1 (u8 0x04)) pk let pk_compressed_to_raw (pk:lbytes 33) : option (lbytes 64) = let pk_x = sub pk 1 32 in match (aff_point_decompress pk) with | Some (x, y) -> Some (concat #_ #32 #32 pk_x (nat_to_bytes_be 32 y)) | None -> None
false
false
Spec.P256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pk_compressed_from_raw (pk: lbytes 64) : lbytes 33
[]
Spec.P256.pk_compressed_from_raw
{ "file_name": "specs/Spec.P256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
pk: Lib.ByteSequence.lbytes 64 -> Lib.ByteSequence.lbytes 33
{ "end_col": 28, "end_line": 221, "start_col": 55, "start_line": 216 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowParse.Tot.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Tot.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Tot", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_all_bytes = tot_parse_all_bytes
let parse_all_bytes =
false
null
false
tot_parse_all_bytes
{ "checked_file": "LowParse.Tot.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Tot.Int.fst.checked", "LowParse.Tot.Combinators.fst.checked", "LowParse.Spec.Bytes.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Tot.Bytes.fst" }
[ "total" ]
[ "LowParse.Spec.Bytes.tot_parse_all_bytes" ]
[]
module LowParse.Tot.Bytes include LowParse.Spec.Bytes include LowParse.Tot.Combinators include LowParse.Tot.Int
false
true
LowParse.Tot.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_all_bytes : LowParse.Spec.Base.tot_parser LowParse.Spec.Bytes.parse_all_bytes_kind FStar.Bytes.bytes
[]
LowParse.Tot.Bytes.parse_all_bytes
{ "file_name": "src/lowparse/LowParse.Tot.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.tot_parser LowParse.Spec.Bytes.parse_all_bytes_kind FStar.Bytes.bytes
{ "end_col": 41, "end_line": 7, "start_col": 22, "start_line": 7 }
FStar.HyperStack.ST.Stack
val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1)
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix
val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix =
true
null
false
clear_matrix s_matrix; clear_matrix e_matrix
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.KEM.clear_matrix", "Prims.unit" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1)
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1)
[]
Hacl.Impl.Frodo.KEM.KeyGen.clear_matrix2
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> s_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> e_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 23, "end_line": 147, "start_col": 2, "start_line": 146 }
FStar.HyperStack.ST.Stack
val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame ()
val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r =
true
null
false
push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame ()
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.IntTypes.uint8", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.crypto_bytes", "Lib.IntTypes.size_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.KEM.clear_words_u8", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Frodo.Params.frodo_shake", "Lib.Sequence.eq_intro", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.Sequence.concat", "Lib.Sequence.create", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.Sequence.sub", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.update_sub", "Lib.Buffer.op_Array_Assignment", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.add", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u8", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len))
[]
Hacl.Impl.Frodo.KEM.KeyGen.frodo_shake_r
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> c: Lib.IntTypes.uint8 -> seed_se: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> output_len: Lib.IntTypes.size_t -> r: Hacl.Impl.Matrix.lbytes output_len -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 53, "start_col": 2, "start_line": 42 }
FStar.HyperStack.ST.Stack
val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let crypto_kem_sk a s pk sk = FP.expand_crypto_secretkeybytes a; let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let sk_p = sub sk 0ul slen1 in crypto_kem_sk1 a s pk sk_p; let h0 = ST.get () in update_sub_f h0 sk slen1 (bytes_pkhash a) (fun h -> FP.frodo_shake a (v (crypto_publickeybytes a)) (as_seq h0 pk) (v (bytes_pkhash a))) (fun _ -> frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) (sub sk slen1 (bytes_pkhash a))); let h1 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (LSeq.sub (as_seq h1 sk) 0 (v slen1)); LSeq.lemma_concat2 (v slen1) (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (v (bytes_pkhash a)) (LSeq.sub (as_seq h1 sk) (v slen1) (v (bytes_pkhash a))) (as_seq h1 sk)
val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes)) let crypto_kem_sk a s pk sk =
true
null
false
FP.expand_crypto_secretkeybytes a; let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let sk_p = sub sk 0ul slen1 in crypto_kem_sk1 a s pk sk_p; let h0 = ST.get () in update_sub_f h0 sk slen1 (bytes_pkhash a) (fun h -> FP.frodo_shake a (v (crypto_publickeybytes a)) (as_seq h0 pk) (v (bytes_pkhash a))) (fun _ -> frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) (sub sk slen1 (bytes_pkhash a))); let h1 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (LSeq.sub (as_seq h1 sk) 0 (v slen1)); LSeq.lemma_concat2 (v slen1) (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (v (bytes_pkhash a)) (LSeq.sub (as_seq h1 sk) (v slen1) (v (bytes_pkhash a))) (as_seq h1 sk)
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.crypto_publickeybytes", "Hacl.Impl.Frodo.Params.crypto_secretkeybytes", "Lib.Sequence.lemma_concat2", "Lib.IntTypes.uint8", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Sequence.sub", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Impl.Frodo.Params.bytes_pkhash", "Prims.unit", "Lib.Sequence.eq_intro", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.update_sub_f", "Spec.Frodo.Params.frodo_shake", "Lib.Sequence.lseq", "Hacl.Impl.Frodo.Params.frodo_shake", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk1", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Subtraction_Bang", "Spec.Frodo.Params.expand_crypto_secretkeybytes" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se)) let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s = push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) let crypto_kem_sk1 a s pk sk = let h1 = ST.get () in FP.expand_crypto_secretkeybytes a; let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in [@inline_let] let sm_len = secretmatrixbytes_len a in let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let s_bytes = sub sk s_pk_len sm_len in update_sub sk 0ul (crypto_bytes a) s; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk; let h3 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); LSeq.lemma_concat3 (v (crypto_bytes a)) (as_seq h1 s) (v (crypto_publickeybytes a)) (as_seq h1 pk) (v sm_len) (as_seq h1 s_bytes) (as_seq h3 sk) inline_for_extraction noextract val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes))
[]
Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> s: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) -> sk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 96, "end_line": 246, "start_col": 2, "start_line": 233 }
FStar.HyperStack.ST.Stack
val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame()
val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix =
true
null
false
FP.params_n_sqr a; push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame ()
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.params_nbar", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Matrix.matrix_add", "Hacl.Impl.Matrix.matrix_mul_s", "Hacl.Impl.Frodo.Params.frodo_gen_matrix", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Matrix.matrix_create", "FStar.HyperStack.ST.push_frame", "Spec.Frodo.Params.params_n_sqr" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
[]
Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} -> seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a -> s_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> e_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> b_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 80, "start_col": 2, "start_line": 74 }
FStar.HyperStack.ST.Stack
val crypto_kem_keypair_: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h coins /\ disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk) (ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let crypto_kem_keypair_ a gen_a coins pk sk = FP.expand_crypto_secretkeybytes a; FP.expand_crypto_secretkeybytes a; let h0 = ST.get () in let s = sub coins 0ul (crypto_bytes a) in let seed_se = sub coins (crypto_bytes a) (crypto_bytes a) in let z = sub coins (2ul *! crypto_bytes a) bytes_seed_a in let seed_a = sub pk 0ul bytes_seed_a in frodo_shake a bytes_seed_a z bytes_seed_a seed_a; let b_bytes = sub pk bytes_seed_a (publicmatrixbytes_len a) in let s_bytes = sub sk (crypto_bytes a +! crypto_publickeybytes a) (secretmatrixbytes_len a) in frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b_bytes s_bytes; let h1 = ST.get () in LSeq.lemma_concat2 (v bytes_seed_a) (as_seq h1 seed_a) (v (publicmatrixbytes_len a)) (as_seq h1 b_bytes) (as_seq h1 pk); crypto_kem_sk a s pk sk
val crypto_kem_keypair_: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h coins /\ disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk) (ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins)) let crypto_kem_keypair_ a gen_a coins pk sk =
true
null
false
FP.expand_crypto_secretkeybytes a; FP.expand_crypto_secretkeybytes a; let h0 = ST.get () in let s = sub coins 0ul (crypto_bytes a) in let seed_se = sub coins (crypto_bytes a) (crypto_bytes a) in let z = sub coins (2ul *! crypto_bytes a) bytes_seed_a in let seed_a = sub pk 0ul bytes_seed_a in frodo_shake a bytes_seed_a z bytes_seed_a seed_a; let b_bytes = sub pk bytes_seed_a (publicmatrixbytes_len a) in let s_bytes = sub sk (crypto_bytes a +! crypto_publickeybytes a) (secretmatrixbytes_len a) in frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b_bytes s_bytes; let h1 = ST.get () in LSeq.lemma_concat2 (v bytes_seed_a) (as_seq h1 seed_a) (v (publicmatrixbytes_len a)) (as_seq h1 b_bytes) (as_seq h1 pk); crypto_kem_sk a s pk sk
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Frodo.Params.crypto_publickeybytes", "Hacl.Impl.Frodo.Params.crypto_secretkeybytes", "Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk", "Prims.unit", "Lib.Sequence.lemma_concat2", "Lib.IntTypes.uint8", "Lib.IntTypes.v", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Hacl.Impl.Frodo.Params.secretmatrixbytes_len", "Lib.Buffer.sub", "Hacl.Impl.Frodo.Params.frodo_shake", "FStar.UInt32.__uint_to_t", "Spec.Frodo.Params.expand_crypto_secretkeybytes" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se)) let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s = push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) let crypto_kem_sk1 a s pk sk = let h1 = ST.get () in FP.expand_crypto_secretkeybytes a; let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in [@inline_let] let sm_len = secretmatrixbytes_len a in let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let s_bytes = sub sk s_pk_len sm_len in update_sub sk 0ul (crypto_bytes a) s; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk; let h3 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); LSeq.lemma_concat3 (v (crypto_bytes a)) (as_seq h1 s) (v (crypto_publickeybytes a)) (as_seq h1 pk) (v sm_len) (as_seq h1 s_bytes) (as_seq h3 sk) inline_for_extraction noextract val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes)) let crypto_kem_sk a s pk sk = FP.expand_crypto_secretkeybytes a; let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let sk_p = sub sk 0ul slen1 in crypto_kem_sk1 a s pk sk_p; let h0 = ST.get () in update_sub_f h0 sk slen1 (bytes_pkhash a) (fun h -> FP.frodo_shake a (v (crypto_publickeybytes a)) (as_seq h0 pk) (v (bytes_pkhash a))) (fun _ -> frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) (sub sk slen1 (bytes_pkhash a))); let h1 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (LSeq.sub (as_seq h1 sk) 0 (v slen1)); LSeq.lemma_concat2 (v slen1) (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (v (bytes_pkhash a)) (LSeq.sub (as_seq h1 sk) (v slen1) (v (bytes_pkhash a))) (as_seq h1 sk) inline_for_extraction noextract val crypto_kem_keypair_: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h coins /\ disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk) (ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val crypto_kem_keypair_: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h coins /\ disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk) (ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins))
[]
Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_keypair_
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} -> coins: Hacl.Impl.Matrix.lbytes (Lib.IntTypes.size 2 *! Hacl.Impl.Frodo.Params.crypto_bytes a +! Hacl.Impl.Frodo.Params.bytes_seed_a) -> pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) -> sk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 25, "end_line": 280, "start_col": 2, "start_line": 264 }
FStar.HyperStack.ST.Stack
val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame ()
val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix =
true
null
false
push_frame (); [@@ inline_let ]let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame ()
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.params_nbar", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.Sample.frodo_sample_matrix", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub", "Lib.IntTypes.uint8", "Lib.IntTypes.op_Star_Bang", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Frodo.KEM.KeyGen.frodo_shake_r", "Lib.IntTypes.u8", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "Hacl.Impl.Frodo.Params.secretmatrixbytes_len", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se))
[]
Hacl.Impl.Frodo.KEM.KeyGen.get_s_e_matrices
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> seed_se: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> s_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> e_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 130, "start_col": 2, "start_line": 124 }
FStar.HyperStack.ST.Stack
val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let crypto_kem_sk1 a s pk sk = let h1 = ST.get () in FP.expand_crypto_secretkeybytes a; let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in [@inline_let] let sm_len = secretmatrixbytes_len a in let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let s_bytes = sub sk s_pk_len sm_len in update_sub sk 0ul (crypto_bytes a) s; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk; let h3 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); LSeq.lemma_concat3 (v (crypto_bytes a)) (as_seq h1 s) (v (crypto_publickeybytes a)) (as_seq h1 pk) (v sm_len) (as_seq h1 s_bytes) (as_seq h3 sk)
val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) let crypto_kem_sk1 a s pk sk =
true
null
false
let h1 = ST.get () in FP.expand_crypto_secretkeybytes a; let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in [@@ inline_let ]let sm_len = secretmatrixbytes_len a in let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let s_bytes = sub sk s_pk_len sm_len in update_sub sk 0ul (crypto_bytes a) s; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk; let h3 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); LSeq.lemma_concat3 (v (crypto_bytes a)) (as_seq h1 s) (v (crypto_publickeybytes a)) (as_seq h1 pk) (v sm_len) (as_seq h1 s_bytes) (as_seq h3 sk)
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.crypto_publickeybytes", "Lib.IntTypes.op_Subtraction_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Frodo.Params.crypto_secretkeybytes", "Hacl.Impl.Frodo.Params.bytes_pkhash", "Lib.Sequence.lemma_concat3", "Lib.IntTypes.uint8", "Lib.IntTypes.v", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Lib.Sequence.eq_intro", "Lib.Sequence.sub", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.update_sub", "FStar.UInt32.__uint_to_t", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "Hacl.Impl.Frodo.Params.secretmatrixbytes_len", "Lib.IntTypes.op_Plus_Bang", "Spec.Frodo.Params.expand_crypto_secretkeybytes" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se)) let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s = push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes))
[]
Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_sk1
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> s: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) -> sk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a -! Hacl.Impl.Frodo.Params.bytes_pkhash a) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 18, "end_line": 215, "start_col": 30, "start_line": 194 }
FStar.HyperStack.ST.Stack
val crypto_kem_keypair: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack uint32 (requires fun h -> live h pk /\ live h sk /\ disjoint state pk /\ disjoint state sk /\ disjoint pk sk) (ensures fun h0 r h1 -> modifies (loc state |+| (loc pk |+| loc sk)) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair a gen_a (as_seq h0 state))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let crypto_kem_keypair a gen_a pk sk = recall state; push_frame(); let coins = create (size 2 *! crypto_bytes a +! bytes_seed_a) (u8 0) in randombytes_ (size 2 *! crypto_bytes a +! bytes_seed_a) coins; crypto_kem_keypair_ a gen_a coins pk sk; clear_words_u8 coins; pop_frame(); u32 0
val crypto_kem_keypair: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack uint32 (requires fun h -> live h pk /\ live h sk /\ disjoint state pk /\ disjoint state sk /\ disjoint pk sk) (ensures fun h0 r h1 -> modifies (loc state |+| (loc pk |+| loc sk)) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair a gen_a (as_seq h0 state)) let crypto_kem_keypair a gen_a pk sk =
true
null
false
recall state; push_frame (); let coins = create (size 2 *! crypto_bytes a +! bytes_seed_a) (u8 0) in randombytes_ (size 2 *! crypto_bytes a +! bytes_seed_a) coins; crypto_kem_keypair_ a gen_a coins pk sk; clear_words_u8 coins; pop_frame (); u32 0
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.crypto_publickeybytes", "Hacl.Impl.Frodo.Params.crypto_secretkeybytes", "Lib.IntTypes.u32", "Lib.IntTypes.uint32", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Hacl.Impl.Frodo.KEM.clear_words_u8", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_keypair_", "Hacl.Frodo.Random.randombytes_", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.add", "Lib.IntTypes.mul", "Lib.IntTypes.mk_int", "Lib.Buffer.create", "Lib.IntTypes.uint8", "Lib.IntTypes.u8", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame", "Lib.Buffer.recall", "FStar.UInt32.__uint_to_t", "Hacl.Frodo.Random.state" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se)) let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s = push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_sk1: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a -! bytes_pkhash a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == LSeq.concat (LSeq.concat (as_seq h0 s) (as_seq h0 pk)) s_bytes)) let crypto_kem_sk1 a s pk sk = let h1 = ST.get () in FP.expand_crypto_secretkeybytes a; let s_pk_len = crypto_bytes a +! crypto_publickeybytes a in [@inline_let] let sm_len = secretmatrixbytes_len a in let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let s_bytes = sub sk s_pk_len sm_len in update_sub sk 0ul (crypto_bytes a) s; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); update_sub sk (crypto_bytes a) (crypto_publickeybytes a) pk; let h3 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h3 sk) 0 (v (crypto_bytes a))) (as_seq h1 s); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v (crypto_bytes a)) (v (crypto_publickeybytes a))) (as_seq h1 pk); LSeq.eq_intro (LSeq.sub (as_seq h3 sk) (v s_pk_len) (v sm_len)) (as_seq h1 s_bytes); LSeq.lemma_concat3 (v (crypto_bytes a)) (as_seq h1 s) (v (crypto_publickeybytes a)) (as_seq h1 pk) (v sm_len) (as_seq h1 s_bytes) (as_seq h3 sk) inline_for_extraction noextract val crypto_kem_sk: a:FP.frodo_alg -> s:lbytes (crypto_bytes a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h s /\ disjoint pk sk /\ disjoint sk s) (ensures fun h0 _ h1 -> modifies (loc sk) h0 h1 /\ (let s_bytes = LSeq.sub (as_seq h0 sk) (v (crypto_bytes a) + v (crypto_publickeybytes a)) (v (secretmatrixbytes_len a)) in as_seq h1 sk == S.crypto_kem_sk a (as_seq h0 s) (as_seq h0 pk) s_bytes)) let crypto_kem_sk a s pk sk = FP.expand_crypto_secretkeybytes a; let slen1 = crypto_secretkeybytes a -! bytes_pkhash a in let sk_p = sub sk 0ul slen1 in crypto_kem_sk1 a s pk sk_p; let h0 = ST.get () in update_sub_f h0 sk slen1 (bytes_pkhash a) (fun h -> FP.frodo_shake a (v (crypto_publickeybytes a)) (as_seq h0 pk) (v (bytes_pkhash a))) (fun _ -> frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) (sub sk slen1 (bytes_pkhash a))); let h1 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (LSeq.sub (as_seq h1 sk) 0 (v slen1)); LSeq.lemma_concat2 (v slen1) (LSeq.sub (as_seq h0 sk) 0 (v slen1)) (v (bytes_pkhash a)) (LSeq.sub (as_seq h1 sk) (v slen1) (v (bytes_pkhash a))) (as_seq h1 sk) inline_for_extraction noextract val crypto_kem_keypair_: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> coins:lbytes (size 2 *! crypto_bytes a +! bytes_seed_a) -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack unit (requires fun h -> live h pk /\ live h sk /\ live h coins /\ disjoint pk sk /\ disjoint coins sk /\ disjoint coins pk) (ensures fun h0 _ h1 -> modifies (loc pk |+| loc sk) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair_ a gen_a (as_seq h0 coins)) let crypto_kem_keypair_ a gen_a coins pk sk = FP.expand_crypto_secretkeybytes a; FP.expand_crypto_secretkeybytes a; let h0 = ST.get () in let s = sub coins 0ul (crypto_bytes a) in let seed_se = sub coins (crypto_bytes a) (crypto_bytes a) in let z = sub coins (2ul *! crypto_bytes a) bytes_seed_a in let seed_a = sub pk 0ul bytes_seed_a in frodo_shake a bytes_seed_a z bytes_seed_a seed_a; let b_bytes = sub pk bytes_seed_a (publicmatrixbytes_len a) in let s_bytes = sub sk (crypto_bytes a +! crypto_publickeybytes a) (secretmatrixbytes_len a) in frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b_bytes s_bytes; let h1 = ST.get () in LSeq.lemma_concat2 (v bytes_seed_a) (as_seq h1 seed_a) (v (publicmatrixbytes_len a)) (as_seq h1 b_bytes) (as_seq h1 pk); crypto_kem_sk a s pk sk inline_for_extraction noextract val crypto_kem_keypair: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack uint32 (requires fun h -> live h pk /\ live h sk /\ disjoint state pk /\ disjoint state sk /\ disjoint pk sk) (ensures fun h0 r h1 -> modifies (loc state |+| (loc pk |+| loc sk)) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair a gen_a (as_seq h0 state))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val crypto_kem_keypair: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> pk:lbytes (crypto_publickeybytes a) -> sk:lbytes (crypto_secretkeybytes a) -> Stack uint32 (requires fun h -> live h pk /\ live h sk /\ disjoint state pk /\ disjoint state sk /\ disjoint pk sk) (ensures fun h0 r h1 -> modifies (loc state |+| (loc pk |+| loc sk)) h0 h1 /\ (as_seq h1 pk, as_seq h1 sk) == S.crypto_kem_keypair a gen_a (as_seq h0 state))
[]
Hacl.Impl.Frodo.KEM.KeyGen.crypto_kem_keypair
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} -> pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) -> sk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_secretkeybytes a) -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint32
{ "end_col": 7, "end_line": 304, "start_col": 2, "start_line": 297 }
FStar.HyperStack.ST.Stack
val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s = push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame ()
val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se)) let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se b s =
true
null
false
push_frame (); let s_matrix = matrix_create (params_n a) params_nbar in let e_matrix = matrix_create (params_n a) params_nbar in get_s_e_matrices a seed_se s_matrix e_matrix; frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b; matrix_to_lbytes s_matrix s; clear_matrix2 a s_matrix e_matrix; pop_frame ()
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "Hacl.Impl.Frodo.Params.secretmatrixbytes_len", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.KEM.KeyGen.clear_matrix2", "Hacl.Impl.Matrix.matrix_to_lbytes", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack", "Hacl.Impl.Frodo.KEM.KeyGen.get_s_e_matrices", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Matrix.matrix_create", "Hacl.Impl.Matrix.matrix_t", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame () inline_for_extraction noextract val get_s_e_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_se s_matrix /\ disjoint seed_se e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1 /\ (as_matrix h1 s_matrix, as_matrix h1 e_matrix) == S.get_s_e_matrices a (as_seq h0 seed_se)) let get_s_e_matrices a seed_se s_matrix e_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len) (u8 0) in frodo_shake_r a (u8 0x5f) seed_se (2ul *! s_bytes_len) r; frodo_sample_matrix a (params_n a) params_nbar (sub r 0ul s_bytes_len) s_matrix; frodo_sample_matrix a (params_n a) params_nbar (sub r s_bytes_len s_bytes_len) e_matrix; pop_frame () inline_for_extraction noextract val clear_matrix2: a:FP.frodo_alg -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h s_matrix /\ live h e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc s_matrix |+| loc e_matrix) h0 h1) let clear_matrix2 a s_matrix e_matrix = clear_matrix s_matrix; clear_matrix e_matrix inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frodo_mul_add_as_plus_e_pack_shake: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> seed_se:lbytes (crypto_bytes a) -> b:lbytes (publicmatrixbytes_len a) -> s:lbytes (secretmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h seed_se /\ live h s /\ live h b /\ disjoint b s /\ disjoint seed_a b /\ disjoint seed_a s /\ disjoint seed_se b /\ disjoint seed_se s) (ensures fun h0 _ h1 -> modifies (loc s |+| loc b) h0 h1 /\ (as_seq h1 b, as_seq h1 s) == S.frodo_mul_add_as_plus_e_pack_shake a gen_a (as_seq h0 seed_a) (as_seq h0 seed_se))
[]
Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} -> seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a -> seed_se: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> b: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.publicmatrixbytes_len a) -> s: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.secretmatrixbytes_len a) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 177, "start_col": 2, "start_line": 168 }
FStar.HyperStack.ST.Stack
val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame ()
val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix b =
true
null
false
push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix; frodo_pack (params_logq a) b_matrix b; pop_frame ()
{ "checked_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.KeyGen.fst" }
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.Pack.frodo_pack", "Hacl.Impl.Frodo.Params.params_logq", "Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Matrix.matrix_create", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Frodo.KEM.KeyGen open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module M = Spec.Matrix module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_shake_r: a:FP.frodo_alg -> c:uint8 -> seed_se:lbytes (crypto_bytes a) -> output_len:size_t -> r:lbytes output_len -> Stack unit (requires fun h -> live h seed_se /\ live h r /\ disjoint seed_se r) (ensures fun h0 _ h1 -> modifies (loc r) h0 h1 /\ as_seq h1 r == S.frodo_shake_r a c (as_seq h0 seed_se) (v output_len)) let frodo_shake_r a c seed_se output_len r = push_frame (); let h0 = ST.get () in let shake_input_seed_se = create (1ul +! crypto_bytes a) (u8 0) in shake_input_seed_se.(0ul) <- c; update_sub shake_input_seed_se 1ul (crypto_bytes a) seed_se; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 0 1) (LSeq.create 1 c); LSeq.eq_intro (LSeq.sub (as_seq h2 shake_input_seed_se) 1 (v (crypto_bytes a))) (as_seq h0 seed_se); LSeq.eq_intro (LSeq.concat (LSeq.create 1 c) (as_seq h0 seed_se)) (as_seq h2 shake_input_seed_se); frodo_shake a (1ul +! crypto_bytes a) shake_input_seed_se output_len r; clear_words_u8 shake_input_seed_se; pop_frame () inline_for_extraction noextract val frodo_mul_add_as_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b_matrix:matrix_t (params_n a) params_nbar -> Stack unit (requires fun h -> live h seed_a /\ live h s_matrix /\ live h e_matrix /\ live h b_matrix /\ disjoint b_matrix seed_a /\ disjoint b_matrix e_matrix /\ disjoint b_matrix s_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b_matrix) h0 h1 /\ as_matrix h1 b_matrix == S.frodo_mul_add_as_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix)) let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix b_matrix = FP.params_n_sqr a; push_frame(); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul_s a_matrix s_matrix b_matrix; matrix_add b_matrix e_matrix; pop_frame() inline_for_extraction noextract val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
false
false
Hacl.Impl.Frodo.KEM.KeyGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frodo_mul_add_as_plus_e_pack: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> s_matrix:matrix_t (params_n a) params_nbar -> e_matrix:matrix_t (params_n a) params_nbar -> b:lbytes (publicmatrixbytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h s_matrix /\ live h e_matrix /\ disjoint seed_a b /\ disjoint b s_matrix /\ disjoint b e_matrix /\ disjoint s_matrix e_matrix) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.frodo_mul_add_as_plus_e_pack a gen_a (as_seq h0 seed_a) (as_matrix h0 s_matrix) (as_matrix h0 e_matrix))
[]
Hacl.Impl.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.KeyGen.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a{Hacl.Impl.Frodo.Params.is_supported gen_a} -> seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a -> s_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> e_matrix: Hacl.Impl.Matrix.matrix_t (Hacl.Impl.Frodo.Params.params_n a) Hacl.Impl.Frodo.Params.params_nbar -> b: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.publicmatrixbytes_len a) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 106, "start_col": 2, "start_line": 102 }
FStar.Pervasives.Lemma
val two_to_nat_to_two (n:nat64) : Lemma (two_to_nat 32 (nat_to_two 32 n) == n) [SMTPat (two_to_nat 32 (nat_to_two 32 n))]
[ { "abbrev": false, "full_module": "Vale.Lib.Meta", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let two_to_nat_to_two (n:nat64) = let n1 = n % (pow2_32) in let n2 = (n/(pow2_32)) % (pow2_32) in let n_f = two_to_nat 32 (Mktwo n1 n2) in assert_norm (n == n1 + n2 * pow2_32)
val two_to_nat_to_two (n:nat64) : Lemma (two_to_nat 32 (nat_to_two 32 n) == n) [SMTPat (two_to_nat 32 (nat_to_two 32 n))] let two_to_nat_to_two (n: nat64) =
false
null
true
let n1 = n % (pow2_32) in let n2 = (n / (pow2_32)) % (pow2_32) in let n_f = two_to_nat 32 (Mktwo n1 n2) in assert_norm (n == n1 + n2 * pow2_32)
{ "checked_file": "Vale.Def.Words.Two.fst.checked", "dependencies": [ "Vale.Lib.Meta.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Def.Words.Two.fst" }
[ "lemma" ]
[ "Vale.Def.Words_s.nat64", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.natN", "Prims.pow2", "Prims.op_Multiply", "Vale.Def.Words.Two_s.two_to_nat", "Vale.Def.Words_s.Mktwo", "Prims.op_Modulus", "Prims.op_Division", "Prims.unit" ]
[]
module Vale.Def.Words.Two open FStar.Mul open Vale.Lib.Meta let lemma_fundamental_div_mod (x:nat64) : Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32)) = () let nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) = let n = n1 + n2 * pow2_32 in assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n); assert (0 <= n); assert (n < pow2_64); assert (two_to_nat 32 (Mktwo n1 n2) == n); assert_norm (pow2_norm 32 == pow2_32); //assert_norm (pow2_norm (2 * 32) == pow2_64); assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32)); lemma_fundamental_div_mod n; ()
false
false
Vale.Def.Words.Two.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val two_to_nat_to_two (n:nat64) : Lemma (two_to_nat 32 (nat_to_two 32 n) == n) [SMTPat (two_to_nat 32 (nat_to_two 32 n))]
[]
Vale.Def.Words.Two.two_to_nat_to_two
{ "file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Vale.Def.Words_s.nat64 -> FStar.Pervasives.Lemma (ensures Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words.Two_s.nat_to_two 32 n) == n) [SMTPat (Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words.Two_s.nat_to_two 32 n))]
{ "end_col": 38, "end_line": 28, "start_col": 33, "start_line": 24 }
FStar.Pervasives.Lemma
val two_to_nat_32_injective (_:unit) : Lemma (forall (x x':two (natN (pow2_norm 32))).{:pattern two_to_nat 32 x; two_to_nat 32 x'} two_to_nat 32 x == two_to_nat 32 x' ==> x == x')
[ { "abbrev": false, "full_module": "Vale.Lib.Meta", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let two_to_nat_32_injective () = generic_injective_proof (two_to_nat 32) (nat_to_two 32) (fun x -> nat_to_two_to_nat x.lo x.hi)
val two_to_nat_32_injective (_:unit) : Lemma (forall (x x':two (natN (pow2_norm 32))).{:pattern two_to_nat 32 x; two_to_nat 32 x'} two_to_nat 32 x == two_to_nat 32 x' ==> x == x') let two_to_nat_32_injective () =
false
null
true
generic_injective_proof (two_to_nat 32) (nat_to_two 32) (fun x -> nat_to_two_to_nat x.lo x.hi)
{ "checked_file": "Vale.Def.Words.Two.fst.checked", "dependencies": [ "Vale.Lib.Meta.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Def.Words.Two.fst" }
[ "lemma" ]
[ "Prims.unit", "Vale.Lib.Meta.generic_injective_proof", "Vale.Def.Words_s.two", "Vale.Def.Words_s.nat32", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Two_s.two_to_nat", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two.nat_to_two_to_nat", "Vale.Def.Words_s.__proj__Mktwo__item__lo", "Vale.Def.Words_s.__proj__Mktwo__item__hi" ]
[]
module Vale.Def.Words.Two open FStar.Mul open Vale.Lib.Meta let lemma_fundamental_div_mod (x:nat64) : Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32)) = () let nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) = let n = n1 + n2 * pow2_32 in assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n); assert (0 <= n); assert (n < pow2_64); assert (two_to_nat 32 (Mktwo n1 n2) == n); assert_norm (pow2_norm 32 == pow2_32); //assert_norm (pow2_norm (2 * 32) == pow2_64); assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32)); lemma_fundamental_div_mod n; () let two_to_nat_to_two (n:nat64) = let n1 = n % (pow2_32) in let n2 = (n/(pow2_32)) % (pow2_32) in let n_f = two_to_nat 32 (Mktwo n1 n2) in assert_norm (n == n1 + n2 * pow2_32)
false
false
Vale.Def.Words.Two.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val two_to_nat_32_injective (_:unit) : Lemma (forall (x x':two (natN (pow2_norm 32))).{:pattern two_to_nat 32 x; two_to_nat 32 x'} two_to_nat 32 x == two_to_nat 32 x' ==> x == x')
[]
Vale.Def.Words.Two.two_to_nat_32_injective
{ "file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures forall (x: Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 32))) (x': Vale.Def.Words_s.two (Vale.Def.Words_s.natN (Vale.Def.Words_s.pow2_norm 32))). {:pattern Vale.Def.Words.Two_s.two_to_nat 32 x; Vale.Def.Words.Two_s.two_to_nat 32 x'} Vale.Def.Words.Two_s.two_to_nat 32 x == Vale.Def.Words.Two_s.two_to_nat 32 x' ==> x == x')
{ "end_col": 96, "end_line": 31, "start_col": 2, "start_line": 31 }
FStar.Pervasives.Lemma
val nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) [SMTPat (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)))]
[ { "abbrev": false, "full_module": "Vale.Lib.Meta", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) = let n = n1 + n2 * pow2_32 in assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n); assert (0 <= n); assert (n < pow2_64); assert (two_to_nat 32 (Mktwo n1 n2) == n); assert_norm (pow2_norm 32 == pow2_32); //assert_norm (pow2_norm (2 * 32) == pow2_64); assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32)); lemma_fundamental_div_mod n; ()
val nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) [SMTPat (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)))] let nat_to_two_to_nat (n1 n2: nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) =
false
null
true
let n = n1 + n2 * pow2_32 in assert_norm (two_to_nat 32 (Mktwo n1 n2) == int_to_natN pow2_64 n); assert (0 <= n); assert (n < pow2_64); assert (two_to_nat 32 (Mktwo n1 n2) == n); assert_norm (pow2_norm 32 == pow2_32); assert_norm (nat_to_two 32 n == Mktwo (n % pow2_32) ((n / pow2_32) % pow2_32)); lemma_fundamental_div_mod n; ()
{ "checked_file": "Vale.Def.Words.Two.fst.checked", "dependencies": [ "Vale.Lib.Meta.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Def.Words.Two.fst" }
[ "lemma" ]
[ "Vale.Def.Words_s.nat32", "Prims.unit", "Vale.Def.Words.Two.lemma_fundamental_div_mod", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words_s.Mktwo", "Prims.op_Modulus", "Vale.Def.Words_s.pow2_32", "Prims.op_Division", "Prims.int", "Vale.Def.Words_s.pow2_norm", "Prims._assert", "Vale.Def.Words.Two_s.two_to_nat", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_64", "Prims.op_LessThanOrEqual", "Vale.Def.Words_s.int_to_natN", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.Def.Words.Two open FStar.Mul open Vale.Lib.Meta let lemma_fundamental_div_mod (x:nat64) : Lemma (x = x % pow2_32 + pow2_32 * ((x / pow2_32) % pow2_32)) = () let nat_to_two_to_nat (n1 n2:nat32) : Lemma
false
false
Vale.Def.Words.Two.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val nat_to_two_to_nat (n1 n2:nat32) : Lemma (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)) == Mktwo n1 n2) [SMTPat (nat_to_two 32 (two_to_nat 32 (Mktwo n1 n2)))]
[]
Vale.Def.Words.Two.nat_to_two_to_nat
{ "file_name": "vale/code/lib/util/Vale.Def.Words.Two.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n1: Vale.Def.Words_s.nat32 -> n2: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures Vale.Def.Words.Two_s.nat_to_two 32 (Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words_s.Mktwo n1 n2)) == Vale.Def.Words_s.Mktwo n1 n2) [ SMTPat (Vale.Def.Words.Two_s.nat_to_two 32 (Vale.Def.Words.Two_s.two_to_nat 32 (Vale.Def.Words_s.Mktwo n1 n2))) ]
{ "end_col": 4, "end_line": 22, "start_col": 3, "start_line": 12 }