file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
listlengths
0
2
mutual_with
listlengths
0
11
ideal_premises
listlengths
0
236
proof_features
listlengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
DoublyLinkedListIface.fst
DoublyLinkedListIface.node_val
val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n))
val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n))
let node_val n = (!*n).DLL.p
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 73, "start_col": 0, "start_line": 72 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedListIface.node 'a -> FStar.HyperStack.ST.StackInline 'a
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.node", "DoublyLinkedList.__proj__Mknode__item__p", "DoublyLinkedList.node", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
false
true
false
false
false
let node_val n =
(!*n).DLL.p
false
Steel.HigherReference.fst
Steel.HigherReference.share_atomic_raw
val share_atomic_raw (#a #uses: _) (#p: perm) (r: ref a {perm_ok p}) (v0: erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> (pts_to_raw r (half_perm p) v0) `star` (pts_to_raw r (half_perm p) v0))
val share_atomic_raw (#a #uses: _) (#p: perm) (r: ref a {perm_ok p}) (v0: erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> (pts_to_raw r (half_perm p) v0) `star` (pts_to_raw r (half_perm p) v0))
let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 247, "start_col": 0, "start_line": 243 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a {Steel.HigherReference.perm_ok p} -> v0: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhostT Prims.unit
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.HigherReference.ref", "Steel.HigherReference.perm_ok", "FStar.Ghost.erased", "Steel.HigherReference.share_atomic_raw_gen", "Steel.FractionalPermission.half_perm", "Prims.unit", "Steel.HigherReference.pts_to_raw", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let share_atomic_raw #a #uses (#p: perm) (r: ref a {perm_ok p}) (v0: erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> (pts_to_raw r (half_perm p) v0) `star` (pts_to_raw r (half_perm p) v0)) =
share_atomic_raw_gen r v0 (half_perm p) (half_perm p)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_new
val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == []))
val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == []))
let dll_new () = B.alloca DLL.empty_list 1ul
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 112, "start_col": 0, "start_line": 111 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u137: Prims.unit -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.dll 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "Prims.unit", "LowStar.Buffer.alloca", "DoublyLinkedList.dll", "DoublyLinkedList.empty_list", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "DoublyLinkedListIface.dll" ]
[]
false
true
false
false
false
let dll_new () =
B.alloca DLL.empty_list 1ul
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.node_update
val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n))
val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n))
let node_update n v = n *= { !*n with DLL.p = v }
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 89, "start_col": 0, "start_line": 88 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedListIface.node 'a -> v: 'a -> FStar.HyperStack.ST.StackInline Prims.unit
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.node", "LowStar.BufferOps.op_Star_Equals", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "Prims.unit", "DoublyLinkedList.Mknode", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.__proj__Mknode__item__blink", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
true
false
false
false
let node_update n v =
n *= { !*n with DLL.p = v }
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.lemma_node_in_valid_dll_is_valid
val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n))
val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n))
let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 134, "start_col": 0, "start_line": 132 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h d)) (ensures DoublyLinkedListIface.node_valid h n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedList.extract_nodelist_contained", "DoublyLinkedListIface.as_list", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.eq2", "FStar.List.Tot.Base.index", "FStar.List.Tot.Properties.index_of", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_node_in_valid_dll_is_valid h d n =
let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_tail
val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d))))
val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d))))
let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 123, "start_col": 0, "start_line": 120 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.node 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedListIface.node", "DoublyLinkedList.dll", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Prims.unit", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedListIface.as_list", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let dll_tail d =
let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_head
val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d)))
val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d)))
let dll_head d = (!*d).DLL.lhead
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 118, "start_col": 0, "start_line": 117 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.node 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedListIface.node", "DoublyLinkedList.dll", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
false
true
false
false
false
let dll_head d =
(!*d).DLL.lhead
false
Steel.HigherReference.fst
Steel.HigherReference.share
val share (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
val share (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 270, "start_col": 0, "start_line": 266 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a -> Steel.Effect.Atomic.SteelGhostT Prims.unit
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.HigherReference.share_gen", "Steel.FractionalPermission.half_perm", "Prims.unit", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let share (#a: Type) #uses (#p: perm) (#v: erased a) (r: ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> (pts_to r (half_perm p) v) `star` (pts_to r (half_perm p) v)) =
share_gen r (half_perm p) (half_perm p)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.is_empty
val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == [])))
val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == [])))
let is_empty d = B.is_null (!*d).DLL.lhead
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 115, "start_col": 0, "start_line": 114 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> FStar.HyperStack.ST.StackInline Prims.bool
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "LowStar.Monotonic.Buffer.is_null", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "Prims.bool", "LowStar.Monotonic.Buffer.mbuffer", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.dll", "LowStar.BufferOps.op_Bang_Star" ]
[]
false
true
false
false
false
let is_empty d =
B.is_null (!*d).DLL.lhead
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._pred_nl_disjoint
val _pred_nl_disjoint : h: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> Type0
let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 265, "start_col": 0, "start_line": 264 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.nodelist_fp0", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip" ]
[ "recursion" ]
false
false
false
true
true
let rec _pred_nl_disjoint (h: HS.mem) (ns: list (node 'a)) =
(DLL.nodelist_fp0 ns) `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h))
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_write
val ghost_write (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a) : SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> ghost_pts_to r full_perm x)
val ghost_write (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a) : SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> ghost_pts_to r full_perm x)
let ghost_write r x = ghost_write_aux (reveal r) (reveal x); rewrite_slprop (pts_to (reveal r) full_perm (hide (reveal x))) (ghost_pts_to r full_perm x) (fun _ -> ())
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 17, "end_line": 494, "start_col": 0, "start_line": 489 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in calc (equiv) { p `star` q; (equiv) { star_commutative p q } q `star` p; (equiv) { equiv_extensional_on_star q r p } r `star` p; (equiv) { star_commutative p r } p `star` r; } let cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let ghost_share_gen r p1 p2 = share_gen (reveal r) p1 p2 let ghost_share r = share (reveal r) let ghost_gather r = gather (reveal r) let ghost_pts_to_injective_eq #_ #_ #p0 #p1 r v0 v1 = higher_ref_pts_to_injective_eq #_ #_ #p0 #p1 #v0 #v1 (reveal r) let ghost_pts_to_perm #a #_ #p #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (ghost_pts_to r p v) (RP.pts_to r v_old `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (RP.pts_to r v_old `star` pure (perm_ok p)) (ghost_pts_to r p v) (fun _ -> ()) let ghost_read #a #u #p #v r = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = as_atomic_action_ghost (sel_action u r v1) in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); x let ghost_write_aux (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:a) : SteelGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm (Ghost.hide x)) = let v_old : erased (fractional a) = Ghost.hide (Some (reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (Mem.upd_action u r v_old v_new); rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm (hide x)) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm (hide x))); pure_star_interp (hp_of (pts_to_raw r full_perm (hide x))) (perm_ok full_perm) m)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ghost_ref a -> x: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhostT Prims.unit
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "Steel.HigherReference.ghost_ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Steel.FractionalPermission.full_perm", "Steel.HigherReference.ghost_pts_to", "Steel.Memory.mem", "Prims.unit", "Steel.HigherReference.ghost_write_aux" ]
[]
false
true
false
false
false
let ghost_write r x =
ghost_write_aux (reveal r) (reveal x); rewrite_slprop (pts_to (reveal r) full_perm (hide (reveal x))) (ghost_pts_to r full_perm x) (fun _ -> ())
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.unchanged_node_vals
val unchanged_node_vals (h0 h1: HS.mem) (ns: list (node 'a)) : GTot prop
val unchanged_node_vals (h0 h1: HS.mem) (ns: list (node 'a)) : GTot prop
let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns'
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 75, "end_line": 101, "start_col": 0, "start_line": 98 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "Prims.l_True", "Prims.l_and", "DoublyLinkedListIface.unchanged_node_val", "DoublyLinkedListIface.unchanged_node_vals", "Prims.prop" ]
[ "recursion" ]
false
false
false
false
true
let rec unchanged_node_vals (h0 h1: HS.mem) (ns: list (node 'a)) : GTot prop =
match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns'
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem
val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl))
val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl))
let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 163, "start_col": 0, "start_line": 157 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> s: LowStar.Monotonic.Buffer.loc -> nl: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.modifies s h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint s (DoublyLinkedList.nodelist_fp0 nl) /\ DoublyLinkedList.nodelist_contained0 h0 nl /\ DoublyLinkedList.nodelist_conn h0 nl) (ensures DoublyLinkedList.nodelist_conn h1 nl)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl =
match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_dll_valid_and_unchanged_through_push
val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 187, "start_col": 0, "start_line": 184 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.Monotonic.HyperStack.fresh_frame h0 h1 ) (ensures DoublyLinkedListIface.dll_valid h1 d /\ d @ h0 == d @ h1) [ SMTPat (DoublyLinkedListIface.dll_valid h0 d); SMTPat (FStar.Monotonic.HyperStack.fresh_frame h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem", "LowStar.Monotonic.Buffer.loc_none", "DoublyLinkedListIface.as_list", "Prims.unit", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem", "LowStar.Monotonic.Buffer.fresh_frame_modifies" ]
[]
true
false
true
false
false
let _auto_dll_valid_and_unchanged_through_push h0 h1 d =
B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_nodelist_disjoint_in_push
val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1))))
val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1))))
let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 175, "start_col": 0, "start_line": 171 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> nl: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires FStar.Monotonic.HyperStack.fresh_frame h0 h1 /\ DoublyLinkedList.nodelist_contained0 h0 nl) (ensures LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedList.nodelist_fp0 nl) (LowStar.Monotonic.Buffer.loc_region_only false (FStar.Monotonic.HyperStack.get_tip h1)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_nodelist_disjoint_in_push", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_nodelist_disjoint_in_push h0 h1 nl =
match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_dll_modified_with_push_pop
val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)]
val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)]
let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 223, "start_col": 0, "start_line": 219 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> h2: FStar.Monotonic.HyperStack.mem -> h3: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.Monotonic.HyperStack.fresh_frame h0 h1 /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_union (DoublyLinkedListIface.fp_dll h0 d) (DoublyLinkedListIface.fp_dll h3 d)) h1 h2 /\ LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h0 d) (LowStar.Monotonic.Buffer.loc_region_only false (FStar.Monotonic.HyperStack.get_tip h2)) /\ LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h3 d) (LowStar.Monotonic.Buffer.loc_region_only false (FStar.Monotonic.HyperStack.get_tip h2)) /\ FStar.Monotonic.HyperStack.get_tip h1 == FStar.Monotonic.HyperStack.get_tip h2 /\ DoublyLinkedListIface.dll_valid h2 d /\ FStar.Monotonic.HyperStack.popped h2 h3) (ensures DoublyLinkedListIface.dll_valid h3 d) [ SMTPat (FStar.Monotonic.HyperStack.fresh_frame h0 h1); SMTPat (FStar.Monotonic.HyperStack.popped h2 h3); SMTPat (DoublyLinkedListIface.dll_valid h3 d) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem", "DoublyLinkedListIface.as_list", "Prims.unit", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem", "LowStar.Monotonic.Buffer.popped_modifies", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip" ]
[]
true
false
true
false
false
let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 =
let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem
val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl))
val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl))
let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 147, "start_col": 0, "start_line": 143 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> s: LowStar.Monotonic.Buffer.loc -> nl: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.modifies s h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint s (DoublyLinkedList.nodelist_fp0 nl) /\ DoublyLinkedList.nodelist_contained0 h0 nl) (ensures DoublyLinkedList.nodelist_contained0 h1 nl)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl =
match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_dll_valid_and_unchanged_through_pop
val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1))
val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1))
let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 201, "start_col": 0, "start_line": 195 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.Monotonic.HyperStack.popped h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h0 d) (LowStar.Monotonic.Buffer.loc_region_only false (FStar.Monotonic.HyperStack.get_tip h0))) (ensures DoublyLinkedListIface.dll_valid h1 d /\ d @ h0 == d @ h1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem", "DoublyLinkedListIface.as_list", "Prims.unit", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "Prims._assert", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.popped_modifies" ]
[]
true
false
true
false
false
let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d =
B.popped_modifies h0 h1; assert ((B.loc_region_only false (HS.get_tip h0)) `B.loc_includes` (B.loc_region_only false (HS.get_tip h0))); let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_unchanged_node_vals_transitive
val _lemma_unchanged_node_vals_transitive (h0 h1 h2: HS.mem) (ns: list (node 'a)) : Lemma (requires ((unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ((unchanged_node_vals h0 h2 ns)))
val _lemma_unchanged_node_vals_transitive (h0 h1 h2: HS.mem) (ns: list (node 'a)) : Lemma (requires ((unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ((unchanged_node_vals h0 h2 ns)))
let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns'
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 261, "start_col": 0, "start_line": 252 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.unchanged_node_vals h0 h1 ns /\ DoublyLinkedListIface.unchanged_node_vals h1 h2 ns) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h2 ns)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_unchanged_node_vals_transitive", "Prims.unit", "Prims.l_and", "DoublyLinkedListIface.unchanged_node_vals", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2: HS.mem) (ns: list (node 'a)) : Lemma (requires ((unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ((unchanged_node_vals h0 h2 ns))) =
match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns'
false
Steel.HigherReference.fst
Steel.HigherReference.higher_ref_pts_to_injective_eq
val higher_ref_pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1: erased a) (r: ref a) : SteelGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
val higher_ref_pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1: erased a) (r: ref a) : SteelGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 64, "end_line": 111, "start_col": 0, "start_line": 108 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.extract_info_raw", "Steel.Effect.Common.star", "Prims.eq2", "Steel.HigherReference.pts_to_ref_injective" ]
[]
false
true
false
false
false
let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r =
extract_info_raw ((pts_to r p0 v0) `star` (pts_to r p1 v1)) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_dll_assign_valid_stays_valid
val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)]
val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)]
let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 81, "end_line": 249, "start_col": 0, "start_line": 247 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> d2: DoublyLinkedList.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedList.dll_valid h0 d2 /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer d) h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer d) (DoublyLinkedList.dll_fp0 d2) /\ LowStar.Monotonic.Buffer.live h0 d /\ d @ h1 == d2) (ensures DoublyLinkedListIface.dll_valid h1 d) [ SMTPat (DoublyLinkedList.dll_valid h0 d2); SMTPat (LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer d) h0 h1); SMTPat (DoublyLinkedListIface.dll_valid h1 d) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedList.dll", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "Prims.unit", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem" ]
[]
true
false
true
false
false
let _auto_dll_assign_valid_stays_valid h0 h1 d d2 =
_lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_dll_fp_disjoint_from_push
val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 233, "start_col": 0, "start_line": 232 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.Monotonic.HyperStack.fresh_frame h0 h1 ) (ensures LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h0 d) (LowStar.Monotonic.Buffer.loc_region_only false (FStar.Monotonic.HyperStack.get_tip h1))) [ SMTPat (DoublyLinkedListIface.dll_valid h0 d); SMTPat (FStar.Monotonic.HyperStack.fresh_frame h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_nodelist_disjoint_in_push", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "DoublyLinkedListIface.op_At", "DoublyLinkedList.dll", "Prims.unit" ]
[]
true
false
true
false
false
let _auto_dll_fp_disjoint_from_push h0 h1 d =
_lemma_nodelist_disjoint_in_push h0 h1 (d @ h0).DLL.nodes
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_unchanged_node_vals_through_push_pop
val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)]
val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)]
let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 288, "start_col": 0, "start_line": 281 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> h2: FStar.Monotonic.HyperStack.mem -> h3: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.unchanged_node_vals h1 h2 ns /\ FStar.Monotonic.HyperStack.fresh_frame h0 h1 /\ FStar.Monotonic.HyperStack.popped h2 h3 /\ DoublyLinkedListIface._pred_nl_disjoint h1 ns /\ FStar.Monotonic.HyperStack.get_tip h1 == FStar.Monotonic.HyperStack.get_tip h2) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 ns /\ DoublyLinkedListIface.unchanged_node_vals h2 h3 ns /\ DoublyLinkedListIface.unchanged_node_vals h0 h3 ns) [ SMTPat (DoublyLinkedListIface.unchanged_node_vals h0 h3 ns); SMTPat (FStar.Monotonic.HyperStack.fresh_frame h0 h1); SMTPat (FStar.Monotonic.HyperStack.popped h2 h3) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "LowStar.Monotonic.Buffer.popped_modifies", "Prims.unit", "DoublyLinkedListIface._auto_unchanged_node_vals_through_push_pop" ]
[ "recursion" ]
false
false
true
false
false
let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 =
match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; B.popped_modifies h2 h3
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_unchanged_node_vals_DLL
val _auto_unchanged_node_vals_DLL (h0 h1: HS.mem) (ns: list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)]
val _auto_unchanged_node_vals_DLL (h0 h1: HS.mem) (ns: list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)]
let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns'
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 317, "start_col": 0, "start_line": 310 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> ns: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires DoublyLinkedList.unchanged_node_vals h0 h1 ns) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 ns) [SMTPat (DoublyLinkedListIface.unchanged_node_vals h0 h1 ns)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._auto_unchanged_node_vals_DLL", "Prims.unit", "DoublyLinkedList.unchanged_node_vals", "Prims.squash", "DoublyLinkedListIface.unchanged_node_vals", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec _auto_unchanged_node_vals_DLL (h0 h1: HS.mem) (ns: list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] =
match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns'
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_pred_nl_disjoint_push
val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)]
let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 307, "start_col": 0, "start_line": 297 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.Monotonic.HyperStack.fresh_frame h0 h1 ) (ensures DoublyLinkedListIface._pred_nl_disjoint h1 (DoublyLinkedListIface.as_list h1 d)) [ SMTPat (DoublyLinkedListIface.dll_valid h0 d); SMTPat (FStar.Monotonic.HyperStack.fresh_frame h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.as_list", "Prims.list", "DoublyLinkedListIface.node", "Prims.unit", "Prims.l_and", "DoublyLinkedList.nodelist_contained", "FStar.Monotonic.HyperStack.fresh_frame", "Prims.squash", "DoublyLinkedListIface._pred_nl_disjoint", "Prims.Nil", "FStar.Pervasives.pattern", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip" ]
[]
false
false
true
false
false
let _auto_pred_nl_disjoint_push h0 h1 d =
let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns: list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_unchanged_node_vals_stays_valid0
val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d)))
val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d)))
let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 80, "end_line": 360, "start_col": 0, "start_line": 359 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer d) h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer d) (DoublyLinkedList.dll_fp0 (d @ h0)) /\ LowStar.Monotonic.Buffer.live h0 d) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 (DoublyLinkedListIface.as_list h0 d))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_unchanged_node_vals_when_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedListIface.as_list", "Prims.unit" ]
[]
true
false
true
false
false
let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d =
_lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_node_in_list_or_null_is_included
val _lemma_node_in_list_or_null_is_included (n: B.pointer_or_null (DLL.node 'a)) (nl: list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (B.loc_buffer n)))
val _lemma_node_in_list_or_null_is_included (n: B.pointer_or_null (DLL.node 'a)) (nl: list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (B.loc_buffer n)))
let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 381, "start_col": 0, "start_line": 375 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: LowStar.Buffer.pointer_or_null (DoublyLinkedList.node 'a) -> nl: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires ~(n == LowStar.Buffer.null) ==> FStar.List.Tot.Base.memP n nl) (ensures LowStar.Monotonic.Buffer.loc_includes (DoublyLinkedList.nodelist_fp0 nl) (LowStar.Monotonic.Buffer.loc_buffer n))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.node", "Prims.list", "DoublyLinkedListIface.node", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "LowStar.Buffer.null", "LowStar.Monotonic.Buffer.loc_includes", "DoublyLinkedList.nodelist_fp0", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "Prims.squash", "DoublyLinkedListIface._lemma_node_in_list_is_included", "Prims.unit", "Prims.l_imp", "FStar.List.Tot.Base.memP", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let _lemma_node_in_list_or_null_is_included (n: B.pointer_or_null (DLL.node 'a)) (nl: list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (B.loc_buffer n))) =
FStar.Classical.arrow_to_impl #(n =!= B.null) #((DLL.nodelist_fp0 nl) `B.loc_includes` (B.loc_buffer n)) (fun _ -> _lemma_node_in_list_is_included n nl)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._auto_unchanged_node_vals_stays_valid
val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))]
val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))]
let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 340, "start_col": 0, "start_line": 331 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1);
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> d2: DoublyLinkedList.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedList.dll_valid h0 d2 /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer d) h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (LowStar.Monotonic.Buffer.loc_buffer d) (DoublyLinkedList.dll_fp0 d2) /\ LowStar.Monotonic.Buffer.live h0 d /\ d @ h1 == d2) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 (DoublyLinkedListIface.as_list h1 d)) [ SMTPat (DoublyLinkedList.dll_valid h0 d2); SMTPat (LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer d) h0 h1); SMTPat (DoublyLinkedListIface.unchanged_node_vals h0 h1 (DoublyLinkedListIface.as_list h1 d) ) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedList.dll", "DoublyLinkedListIface.as_list", "Prims.list", "DoublyLinkedListIface.node", "Prims.unit", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.nodelist_fp0", "Prims.squash", "DoublyLinkedListIface.unchanged_node_vals", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 =
let rec aux nl : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ (DLL.nodelist_fp0 nl) `B.loc_disjoint` (B.loc_buffer d))) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_append_contains
val _lemma_append_contains (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2)))
val _lemma_append_contains (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2)))
let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 462, "start_col": 0, "start_line": 455 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> l1: Prims.list (DoublyLinkedListIface.node 'a) -> l2: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (ensures DoublyLinkedList.nodelist_contained h0 (l1 @ l2) <==> DoublyLinkedList.nodelist_contained h0 l1 /\ DoublyLinkedList.nodelist_contained h0 l2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_append_contains", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "DoublyLinkedList.nodelist_contained", "FStar.List.Tot.Base.append", "Prims.l_and", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_append_contains (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) =
match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_append_g_node_vals
val _lemma_append_g_node_vals (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((g_node_vals h0 (l1 `L.append` l2) == (g_node_vals h0 l1) `L.append` (g_node_vals h0 l2))))
val _lemma_append_g_node_vals (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((g_node_vals h0 (l1 `L.append` l2) == (g_node_vals h0 l1) `L.append` (g_node_vals h0 l2))))
let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 471, "start_col": 0, "start_line": 465 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> l1: Prims.list (DoublyLinkedListIface.node 'a) -> l2: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (ensures DoublyLinkedListIface.g_node_vals h0 (l1 @ l2) == DoublyLinkedListIface.g_node_vals h0 l1 @ DoublyLinkedListIface.g_node_vals h0 l2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_append_g_node_vals", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "DoublyLinkedListIface.g_node_vals", "FStar.List.Tot.Base.append", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_append_g_node_vals (h0: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((g_node_vals h0 (l1 `L.append` l2) == (g_node_vals h0 l1) `L.append` (g_node_vals h0 l2)))) =
match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2
false
Steel.HigherReference.fst
Steel.HigherReference.intro_pts_to
val intro_pts_to (p: perm) (#a #uses: _) (#v: erased a) (r: ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True)
val intro_pts_to (p: perm) (#a #uses: _) (#v: erased a) (r: ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True)
let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 123, "start_col": 0, "start_line": 116 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Steel.FractionalPermission.perm -> r: Steel.HigherReference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.FractionalPermission.perm", "Steel.Memory.inames", "FStar.Ghost.erased", "Steel.HigherReference.ref", "Steel.Effect.Atomic.rewrite_slprop", "Steel.HigherReference.pts_to'", "Steel.HigherReference.pts_to", "FStar.Ghost.reveal", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.HigherReference.perm_ok", "Steel.HigherReference.pts_to_raw", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
let intro_pts_to (p: perm) #a #uses (#v: erased a) (r: ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) =
intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ())
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_unchanged_node_vals_maintains_changes
val _lemma_unchanged_node_vals_maintains_changes (h0 h1: HS.mem) (l: list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l))
val _lemma_unchanged_node_vals_maintains_changes (h0 h1: HS.mem) (l: list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l))
let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 452, "start_col": 0, "start_line": 445 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> l: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires DoublyLinkedList.nodelist_contained h0 l /\ DoublyLinkedListIface.unchanged_node_vals h0 h1 l) (ensures DoublyLinkedListIface.g_node_vals h1 l == DoublyLinkedListIface.g_node_vals h0 l)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_unchanged_node_vals_maintains_changes", "Prims.unit", "Prims.l_and", "DoublyLinkedList.nodelist_contained", "DoublyLinkedListIface.unchanged_node_vals", "Prims.squash", "Prims.eq2", "DoublyLinkedListIface.g_node_vals", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1: HS.mem) (l: list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) =
match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_node_in_list_is_included
val _lemma_node_in_list_is_included (n: node 'a) (nl: list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (fp_node n)))
val _lemma_node_in_list_is_included (n: node 'a) (nl: list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (fp_node n)))
let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 372, "start_col": 0, "start_line": 363 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedListIface.node 'a -> nl: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.memP n nl) (ensures LowStar.Monotonic.Buffer.loc_includes (DoublyLinkedList.nodelist_fp0 nl) (DoublyLinkedListIface.fp_node n))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "DoublyLinkedListIface.node", "Prims.list", "FStar.Classical.or_elim", "Prims.eq2", "Prims.l_not", "Prims.unit", "LowStar.Monotonic.Buffer.loc_includes", "DoublyLinkedList.nodelist_fp0", "DoublyLinkedListIface.fp_node", "Prims.l_False", "DoublyLinkedListIface._lemma_node_in_list_is_included", "FStar.List.Tot.Base.memP", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_node_in_list_is_included (n: node 'a) (nl: list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures ((DLL.nodelist_fp0 nl) `B.loc_includes` (fp_node n))) =
match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> (DLL.nodelist_fp0 nl) `B.loc_includes` (fp_node n)) (fun (_: (_: unit { match _ with | _ -> n == n' | _ -> False })) -> ()) (fun (_: (_: unit { match _ with | _ -> n =!= n' | _ -> False })) -> _lemma_node_in_list_is_included n ns)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_unchanged_node_vals_append
val _lemma_unchanged_node_vals_append (h0 h1: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2))))
val _lemma_unchanged_node_vals_append (h0 h1: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2))))
let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 481, "start_col": 0, "start_line": 474 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> l1: Prims.list (DoublyLinkedListIface.node 'a) -> l2: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 (l1 @ l2) <==> DoublyLinkedListIface.unchanged_node_vals h0 h1 l1 /\ DoublyLinkedListIface.unchanged_node_vals h0 h1 l2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_unchanged_node_vals_append", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "DoublyLinkedListIface.unchanged_node_vals", "FStar.List.Tot.Base.append", "Prims.l_and", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_unchanged_node_vals_append (h0 h1: HS.mem) (l1 l2: list (node 'a)) : Lemma (ensures ((unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) =
match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_length_g_node_vals
val _lemma_length_g_node_vals (h0: HS.mem) (l: list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l)
val _lemma_length_g_node_vals (h0: HS.mem) (l: list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l)
let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 514, "start_col": 0, "start_line": 508 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> l: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.length (DoublyLinkedListIface.g_node_vals h0 l) = FStar.List.Tot.Base.length l)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_length_g_node_vals", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.List.Tot.Base.length", "DoublyLinkedListIface.g_node_vals", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_length_g_node_vals (h0: HS.mem) (l: list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) =
match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_extract_unchanged_node_val
val _lemma_extract_unchanged_node_val (h0 h1: HS.mem) (n: node 'a) (l: list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n))
val _lemma_extract_unchanged_node_val (h0 h1: HS.mem) (n: node 'a) (l: list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n))
let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 74, "end_line": 491, "start_col": 0, "start_line": 484 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> l: Prims.list (DoublyLinkedListIface.node 'a) -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.unchanged_node_vals h0 h1 l /\ FStar.List.Tot.Base.memP n l) (ensures DoublyLinkedListIface.unchanged_node_val h0 h1 n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "Prims.list", "FStar.Classical.or_elim", "Prims.eq2", "Prims.l_not", "Prims.unit", "DoublyLinkedListIface.unchanged_node_val", "Prims.l_False", "DoublyLinkedListIface._lemma_extract_unchanged_node_val", "Prims.l_and", "DoublyLinkedListIface.unchanged_node_vals", "FStar.List.Tot.Base.memP", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_extract_unchanged_node_val (h0 h1: HS.mem) (n: node 'a) (l: list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) =
let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_: (_: unit { match _ with | _ -> n == h | _ -> False })) -> ()) (fun (_: (_: unit { match _ with | _ -> n =!= h | _ -> False })) -> _lemma_extract_unchanged_node_val h0 h1 n t)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_split_using_splitAt
val _lemma_split_using_splitAt (l: list 'a) (x: 'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l))
val _lemma_split_using_splitAt (l: list 'a) (x: 'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l))
let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 505, "start_col": 0, "start_line": 494 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> x: 'a -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.memP x l) (ensures FStar.List.Tot.Properties.split_using l x == FStar.List.Tot.Base.splitAt (FStar.List.Tot.Properties.index_of l x) l)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "FStar.Classical.arrow_to_impl", "FStar.List.Tot.Base.memP", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Properties.split_using", "FStar.List.Tot.Base.splitAt", "FStar.List.Tot.Properties.index_of", "Prims.squash", "DoublyLinkedListIface._lemma_split_using_splitAt", "Prims.unit", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_split_using_splitAt (l: list 'a) (x: 'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) =
match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_insertion_maintains_unchanged_node_vals
val _lemma_insertion_maintains_unchanged_node_vals (h0 h1: HS.mem) (l1 l2: list (node 'a)) (x0 x1: node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1))
val _lemma_insertion_maintains_unchanged_node_vals (h0 h1: HS.mem) (l1 l2: list (node 'a)) (x0 x1: node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1))
let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 82, "end_line": 441, "start_col": 0, "start_line": 429 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> l1: Prims.list (DoublyLinkedListIface.node 'a) -> l2: Prims.list (DoublyLinkedListIface.node 'a) -> x0: DoublyLinkedListIface.node 'a -> x1: DoublyLinkedListIface.node 'a -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.memP x0 l1 /\ (l2 == DoublyLinkedList._l_insert_before x0 l1 x1 \/ l2 == DoublyLinkedList._l_insert_after x0 l1 x1) /\ DoublyLinkedListIface.unchanged_node_vals h0 h1 l2) (ensures DoublyLinkedListIface.unchanged_node_vals h0 h1 l1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "DoublyLinkedListIface.unchanged_node_vals", "Prims.squash", "DoublyLinkedListIface._lemma_insertion_maintains_unchanged_node_vals", "FStar.List.Tot.Base.tl", "Prims.unit", "Prims.l_and", "FStar.List.Tot.Base.memP", "Prims.l_or", "DoublyLinkedList._l_insert_before", "DoublyLinkedList._l_insert_after", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1: HS.mem) (l1 l2: list (node 'a)) (x0 x1: node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) =
match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.next_node
val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1)))
val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1)))
let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 552, "start_col": 0, "start_line": 548 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.node 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedList.node", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Prims.unit", "DoublyLinkedList.extract_nodelist_conn", "DoublyLinkedListIface.as_list", "FStar.List.Tot.Properties.index_of", "DoublyLinkedListIface.lemma_node_in_valid_dll_is_valid", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let next_node d n =
let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_insertion_maintains_memP
val _lemma_insertion_maintains_memP (l1 l2: list 'a) (x0 x1 x: 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2))
val _lemma_insertion_maintains_memP (l1 l2: list 'a) (x0 x1 x: 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2))
let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 63, "end_line": 426, "start_col": 0, "start_line": 413 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list 'a -> l2: Prims.list 'a -> x0: 'a -> x1: 'a -> x: 'a -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.memP x0 l1 /\ (l2 == DoublyLinkedList._l_insert_before x0 l1 x1 \/ l2 == DoublyLinkedList._l_insert_after x0 l1 x1) /\ (FStar.List.Tot.Base.memP x l1 \/ x == x1)) (ensures FStar.List.Tot.Base.memP x l2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "FStar.Classical.or_elim", "Prims.l_or", "Prims.eq2", "Prims.l_and", "Prims.l_not", "Prims.unit", "FStar.List.Tot.Base.memP", "Prims.l_False", "DoublyLinkedListIface._lemma_insertion_maintains_memP", "FStar.List.Tot.Base.tl", "DoublyLinkedList._l_insert_before", "DoublyLinkedList._l_insert_after", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec _lemma_insertion_maintains_memP (l1 l2: list 'a) (x0 x1 x: 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) =
match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_: (_: unit { match _ with | _ -> x0' == x0 \/ x0' == x | _ -> False })) -> ()) (fun (_: (_: unit { match _ with | _ -> x0' =!= x0 /\ x0' =!= x | _ -> False })) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_prev_node_in_list
val _lemma_prev_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.blink in n' =!= B.null ==> n' `L.memP` (as_list h d)))
val _lemma_prev_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.blink in n' =!= B.null ==> n' `L.memP` (as_list h d)))
let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 395, "start_col": 0, "start_line": 384 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h d)) (ensures (let n' = Mknode?.blink (n @ h) in ~(n' == LowStar.Buffer.null) ==> FStar.List.Tot.Base.memP n' (DoublyLinkedListIface.as_list h d)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "DoublyLinkedListIface.dll", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "DoublyLinkedList.node", "LowStar.Buffer.null", "Prims.l_and", "FStar.List.Tot.Base.memP", "Prims.squash", "DoublyLinkedList.extract_nodelist_conn", "Prims.op_Subtraction", "FStar.List.Tot.Properties.index_of", "Prims.unit", "DoublyLinkedListIface.lemma_node_in_valid_dll_is_valid", "Prims.list", "DoublyLinkedListIface.as_list", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedListIface.op_At", "DoublyLinkedListIface.dll_valid", "Prims.l_imp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let _lemma_prev_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.blink in n' =!= B.null ==> n' `L.memP` (as_list h d))) =
let n' = (n @ h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1))
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.has_prev
val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0)))
val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0)))
let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 546, "start_col": 0, "start_line": 533 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.HyperStack.ST.StackInline Prims.bool
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "Prims.unit", "FStar.Classical.or_elim", "Prims.b2t", "Prims.op_Negation", "Prims.l_iff", "Prims.op_GreaterThan", "FStar.List.Tot.Properties.index_of", "DoublyLinkedListIface.as_list", "DoublyLinkedList._lemma_all_nodes_are_unique", "DoublyLinkedList._lemma_only_head_can_point_left_to_null", "Prims.bool", "LowStar.Monotonic.Buffer.is_null", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.mbuffer", "DoublyLinkedList.__proj__Mknode__item__blink", "LowStar.BufferOps.op_Bang_Star", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.lemma_dll_links_contained", "DoublyLinkedListIface.op_At", "DoublyLinkedList.dll", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let has_prev d n =
let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d @ h0) ((as_list h0 d) `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> (as_list h0 d) `L.index_of` n > 0) (fun (_: (_: unit { match _ with | _ -> y | _ -> False })) -> ()) (fun (_: (_: unit { match _ with | _ -> not y | _ -> False })) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) ((as_list h0 d) `L.index_of` n) 0); y
false
DoublyLinkedListIface.fst
DoublyLinkedListIface._lemma_next_node_in_list
val _lemma_next_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.flink in n' =!= B.null ==> n' `L.memP` (as_list h d)))
val _lemma_next_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.flink in n' =!= B.null ==> n' `L.memP` (as_list h d)))
let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 410, "start_col": 0, "start_line": 398 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h d)) (ensures (let n' = Mknode?.flink (n @ h) in ~(n' == LowStar.Buffer.null) ==> FStar.List.Tot.Base.memP n' (DoublyLinkedListIface.as_list h d)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "DoublyLinkedListIface.dll", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "DoublyLinkedList.node", "LowStar.Buffer.null", "Prims.l_and", "FStar.List.Tot.Base.memP", "Prims.squash", "DoublyLinkedList.extract_nodelist_conn", "FStar.List.Tot.Properties.index_of", "Prims.unit", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedListIface.lemma_node_in_valid_dll_is_valid", "Prims.list", "DoublyLinkedListIface.as_list", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedListIface.op_At", "DoublyLinkedListIface.dll_valid", "Prims.l_imp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let _lemma_next_node_in_list (h: HS.mem) (n: node 'a) (d: dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` (as_list h d))) (ensures (let n' = (n @ h).DLL.flink in n' =!= B.null ==> n' `L.memP` (as_list h d))) =
let n' = (n @ h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n))
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.prev_node
val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1)))
val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1)))
let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 558, "start_col": 0, "start_line": 554 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.node 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedList.__proj__Mknode__item__blink", "DoublyLinkedList.node", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Prims.unit", "DoublyLinkedList.extract_nodelist_conn", "DoublyLinkedListIface.as_list", "Prims.op_Subtraction", "FStar.List.Tot.Properties.index_of", "DoublyLinkedListIface.lemma_node_in_valid_dll_is_valid", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let prev_node d n =
let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.has_next
val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)))
val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)))
let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 531, "start_col": 0, "start_line": 518 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.HyperStack.ST.StackInline Prims.bool
FStar.HyperStack.ST.StackInline
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "Prims.unit", "FStar.Classical.or_elim", "Prims.b2t", "Prims.op_Negation", "Prims.l_iff", "Prims.op_LessThan", "FStar.List.Tot.Properties.index_of", "DoublyLinkedListIface.as_list", "Prims.op_Subtraction", "FStar.List.Tot.Base.length", "DoublyLinkedList._lemma_all_nodes_are_unique", "DoublyLinkedList._lemma_only_tail_can_point_right_to_null", "Prims.bool", "LowStar.Monotonic.Buffer.is_null", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.mbuffer", "DoublyLinkedList.__proj__Mknode__item__flink", "LowStar.BufferOps.op_Bang_Star", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.lemma_dll_links_contained", "DoublyLinkedListIface.op_At", "DoublyLinkedList.dll", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let has_next d n =
let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d @ h0) ((as_list h0 d) `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> (as_list h0 d) `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_: (_: unit { match _ with | _ -> y | _ -> False })) -> ()) (fun (_: (_: unit { match _ with | _ -> not y | _ -> False })) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) ((as_list h0 d) `L.index_of` n) (L.length (as_list h0 d) - 1)); y
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_dll_remains_valid_upon_staying_unchanged
val auto_dll_remains_valid_upon_staying_unchanged (h0 h1:HS.mem) (l:B.loc) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ B.modifies l h0 h1 /\ B.loc_disjoint (fp_dll h0 d) l)) (ensures (dll_valid h1 d)) [SMTPat (dll_valid h1 d); SMTPat (B.modifies l h0 h1)]
val auto_dll_remains_valid_upon_staying_unchanged (h0 h1:HS.mem) (l:B.loc) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ B.modifies l h0 h1 /\ B.loc_disjoint (fp_dll h0 d) l)) (ensures (dll_valid h1 d)) [SMTPat (dll_valid h1 d); SMTPat (B.modifies l h0 h1)]
let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 63, "end_line": 890, "start_col": 0, "start_line": 888 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> l: LowStar.Monotonic.Buffer.loc -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ LowStar.Monotonic.Buffer.modifies l h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h0 d) l) (ensures DoublyLinkedListIface.dll_valid h1 d) [ SMTPat (DoublyLinkedListIface.dll_valid h1 d); SMTPat (LowStar.Monotonic.Buffer.modifies l h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_nodelist_conn_in_unmodified_mem", "DoublyLinkedListIface.as_list", "Prims.unit", "DoublyLinkedListIface._lemma_nodelist_contained_in_unmodified_mem" ]
[]
true
false
true
false
false
let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d =
_lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.domain
val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a
val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a
let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 50, "start_col": 0, "start_line": 48 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> FStar.FiniteSet.Base.set a
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t" ]
[]
false
false
false
false
false
let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a =
let (| keys , _ |) = m in keys
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.cardinality
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat
val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat
let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 77, "start_col": 0, "start_line": 76 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.FiniteSet.Base.cardinality", "FStar.FiniteMap.Base.domain", "Prims.nat" ]
[]
false
false
false
false
false
let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat =
FSet.cardinality (domain m)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.values
val values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop)
val values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop)
let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 84, "start_col": 0, "start_line": 83 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> Prims.GTot (_: b -> Prims.prop)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.l_Exists", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.FiniteMap.Base.elements", "FStar.Pervasives.Native.Some", "Prims.prop" ]
[]
false
false
false
false
false
let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) =
fun value -> exists key. ((elements m) key == Some value)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.items
val items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop)
val items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop)
let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item))
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 91, "start_col": 0, "start_line": 90 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> Prims.GTot (_: (a * b) -> Prims.prop)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.Pervasives.Native.tuple2", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.FiniteMap.Base.elements", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.snd", "Prims.prop" ]
[]
false
false
false
false
false
let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) =
fun item -> ((elements m) (fst item) == Some (snd item))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.glue
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b
val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b
let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 105, "start_col": 0, "start_line": 104 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
keys: FStar.FiniteSet.Base.set a -> f: FStar.FiniteMap.Base.setfun_t a b keys -> FStar.FiniteMap.Base.map a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "Prims.Mkdtuple2", "FStar.FiniteMap.Base.map" ]
[]
false
false
false
false
false
let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b =
(| keys, f |)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_dll_as_payload_list_staying_unchanged
val auto_dll_as_payload_list_staying_unchanged (h0 h1:HS.mem) (l:B.loc) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ B.modifies l h0 h1 /\ B.loc_disjoint (fp_dll h0 d) l)) (ensures (as_payload_list h1 d == as_payload_list h0 d)) [SMTPat (as_payload_list h1 d); SMTPat (B.modifies l h0 h1)]
val auto_dll_as_payload_list_staying_unchanged (h0 h1:HS.mem) (l:B.loc) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ B.modifies l h0 h1 /\ B.loc_disjoint (fp_dll h0 d) l)) (ensures (as_payload_list h1 d == as_payload_list h0 d)) [SMTPat (as_payload_list h1 d); SMTPat (B.modifies l h0 h1)]
let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d = let rec aux loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 924, "start_col": 0, "start_line": 914 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d) let auto_node_remains_valid_upon_staying_unchanged h0 h1 l n = () let auto_node_remains_unchanged_upon_staying_unchanged_val h0 h1 n = () /// Automatic footprint maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_fp_upon_staying_unchanged h0 h1 l d = () /// Automatic value maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_as_list_staying_unchanged h0 h1 l d =()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> l: LowStar.Monotonic.Buffer.loc -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ LowStar.Monotonic.Buffer.modifies l h0 h1 /\ LowStar.Monotonic.Buffer.loc_disjoint (DoublyLinkedListIface.fp_dll h0 d) l) (ensures DoublyLinkedListIface.as_payload_list h1 d == DoublyLinkedListIface.as_payload_list h0 d) [ SMTPat (DoublyLinkedListIface.as_payload_list h1 d); SMTPat (LowStar.Monotonic.Buffer.modifies l h0 h1) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.as_list", "Prims.list", "DoublyLinkedListIface.node", "Prims.unit", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "DoublyLinkedList.nodelist_contained", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.nodelist_fp0", "Prims.squash", "Prims.eq2", "DoublyLinkedListIface.g_node_vals", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d =
let rec aux loc nl : Lemma (requires (B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.disjoint
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop
val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop
let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 146, "start_col": 0, "start_line": 145 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m1: FStar.FiniteMap.Base.map a b -> m2: FStar.FiniteMap.Base.map a b -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.l_and", "FStar.FiniteSet.Base.disjoint", "FStar.FiniteMap.Base.domain", "Prims.l_True", "Prims.prop" ]
[]
false
false
false
false
true
let disjoint (#a: eqtype) (#b: Type u#b) (m1 m2: map a b) : prop =
FSet.disjoint (domain m1) (domain m2) /\ True
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if6
val test_if6 (b: bool) : SteelT ref emp (fun r -> ptr r)
val test_if6 (b: bool) : SteelT ref emp (fun r -> ptr r)
let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r) = let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 131, "start_col": 0, "start_line": 127 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ()) let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> Steel.Effect.SteelT SteelFramingTestSuite.ref
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.ref", "Prims.unit", "SteelFramingTestSuite.write", "Prims.int", "SteelFramingTestSuite.read", "SteelFramingTestSuite.alloc", "Steel.Effect.Common.emp", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if6 (b: bool) : SteelT ref emp (fun r -> ptr r) =
let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.equal
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop
val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop
let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 139, "start_col": 0, "start_line": 138 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m1: FStar.FiniteMap.Base.map a b -> m2: FStar.FiniteMap.Base.map a b -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.l_and", "FStar.FunctionalExtensionality.feq", "FStar.Pervasives.Native.option", "FStar.FiniteMap.Base.elements", "Prims.l_True", "Prims.prop" ]
[]
false
false
false
false
true
let equal (#a: eqtype) (#b: Type u#b) (m1 m2: map a b) : prop =
feq (elements m1) (elements m2) /\ True
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_node_in_list_is_valid
val auto_node_in_list_is_valid (h0:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d)) (ensures (node_valid h0 n)) [SMTPat (node_valid h0 n); SMTPat (dll_valid h0 d)]
val auto_node_in_list_is_valid (h0:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d)) (ensures (node_valid h0 n)) [SMTPat (node_valid h0 n); SMTPat (dll_valid h0 d)]
let auto_node_in_list_is_valid h0 n d = DLL.extract_nodelist_contained h0 (as_list h0 d) (as_list h0 d `L.index_of` n)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 80, "end_line": 939, "start_col": 0, "start_line": 938 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d) let auto_node_remains_valid_upon_staying_unchanged h0 h1 l n = () let auto_node_remains_unchanged_upon_staying_unchanged_val h0 h1 n = () /// Automatic footprint maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_fp_upon_staying_unchanged h0 h1 l d = () /// Automatic value maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_as_list_staying_unchanged h0 h1 l d =() let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d = let rec aux loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d) let auto_node_val_staying_unchanged h0 h1 l n = () /// Properties of nodes inside and outside lists /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_node_in_list_is_included h0 n d = _lemma_node_in_list_is_included n (as_list h0 d)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h0 d)) (ensures DoublyLinkedListIface.node_valid h0 n) [ SMTPat (DoublyLinkedListIface.node_valid h0 n); SMTPat (DoublyLinkedListIface.dll_valid h0 d) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "DoublyLinkedListIface.dll", "DoublyLinkedList.extract_nodelist_contained", "DoublyLinkedListIface.as_list", "FStar.List.Tot.Properties.index_of", "Prims.unit" ]
[]
true
false
true
false
false
let auto_node_in_list_is_valid h0 n d =
DLL.extract_nodelist_contained h0 (as_list h0 d) ((as_list h0 d) `L.index_of` n)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_node_in_list_is_included
val auto_node_in_list_is_included (h0:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d)) (ensures (B.loc_includes (fp_dll h0 d) (fp_node n))) [SMTPat (B.loc_includes (fp_dll h0 d) (fp_node n))]
val auto_node_in_list_is_included (h0:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d)) (ensures (B.loc_includes (fp_dll h0 d) (fp_node n))) [SMTPat (B.loc_includes (fp_dll h0 d) (fp_node n))]
let auto_node_in_list_is_included h0 n d = _lemma_node_in_list_is_included n (as_list h0 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 936, "start_col": 0, "start_line": 935 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d) let auto_node_remains_valid_upon_staying_unchanged h0 h1 l n = () let auto_node_remains_unchanged_upon_staying_unchanged_val h0 h1 n = () /// Automatic footprint maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_fp_upon_staying_unchanged h0 h1 l d = () /// Automatic value maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_as_list_staying_unchanged h0 h1 l d =() let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d = let rec aux loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d) let auto_node_val_staying_unchanged h0 h1 l n = () /// Properties of nodes inside and outside lists /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> d: DoublyLinkedListIface.dll 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h0 d)) (ensures LowStar.Monotonic.Buffer.loc_includes (DoublyLinkedListIface.fp_dll h0 d) (DoublyLinkedListIface.fp_node n)) [ SMTPat (LowStar.Monotonic.Buffer.loc_includes (DoublyLinkedListIface.fp_dll h0 d) (DoublyLinkedListIface.fp_node n)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "DoublyLinkedListIface.dll", "DoublyLinkedListIface._lemma_node_in_list_is_included", "DoublyLinkedListIface.as_list", "Prims.unit" ]
[]
true
false
true
false
false
let auto_node_in_list_is_included h0 n d =
_lemma_node_in_list_is_included n (as_list h0 d)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_unchanged_node_connections_list_unchanged
val auto_unchanged_node_connections_list_unchanged (h0 h1:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d /\ B.modifies (fp_node n) h0 h1 /\ unchanged_node_connections h0 h1 n)) (ensures (as_list h1 d == as_list h0 d)) [SMTPat (as_list h1 d); SMTPat (B.modifies (fp_node n) h0 h1); SMTPat (unchanged_node_connections h0 h1 n)]
val auto_unchanged_node_connections_list_unchanged (h0 h1:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d /\ B.modifies (fp_node n) h0 h1 /\ unchanged_node_connections h0 h1 n)) (ensures (as_list h1 d == as_list h0 d)) [SMTPat (as_list h1 d); SMTPat (B.modifies (fp_node n) h0 h1); SMTPat (unchanged_node_connections h0 h1 n)]
let auto_unchanged_node_connections_list_unchanged h0 h1 d n = assert (B.loc_disjoint (B.loc_buffer d) (DLL.dll_fp0 (d@h0))); DLL.extract_nodelist_fp0 (as_list h0 d) (as_list h0 d `L.index_of` n); assert (B.loc_disjoint (B.loc_buffer d) (B.loc_buffer n))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 951, "start_col": 0, "start_line": 948 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d) let auto_node_remains_valid_upon_staying_unchanged h0 h1 l n = () let auto_node_remains_unchanged_upon_staying_unchanged_val h0 h1 n = () /// Automatic footprint maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_fp_upon_staying_unchanged h0 h1 l d = () /// Automatic value maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_as_list_staying_unchanged h0 h1 l d =() let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d = let rec aux loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d) let auto_node_val_staying_unchanged h0 h1 l n = () /// Properties of nodes inside and outside lists /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_node_in_list_is_included h0 n d = _lemma_node_in_list_is_included n (as_list h0 d) let auto_node_in_list_is_valid h0 n d = DLL.extract_nodelist_contained h0 (as_list h0 d) (as_list h0 d `L.index_of` n) /// Properties related to unchanged connections /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h0 d) /\ LowStar.Monotonic.Buffer.modifies (DoublyLinkedListIface.fp_node n) h0 h1 /\ DoublyLinkedListIface.unchanged_node_connections h0 h1 n) (ensures DoublyLinkedListIface.as_list h1 d == DoublyLinkedListIface.as_list h0 d) [ SMTPat (DoublyLinkedListIface.as_list h1 d); SMTPat (LowStar.Monotonic.Buffer.modifies (DoublyLinkedListIface.fp_node n) h0 h1); SMTPat (DoublyLinkedListIface.unchanged_node_connections h0 h1 n) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "Prims._assert", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.node", "Prims.unit", "DoublyLinkedList.extract_nodelist_fp0", "DoublyLinkedListIface.as_list", "FStar.List.Tot.Properties.index_of", "DoublyLinkedList.dll_fp0", "DoublyLinkedListIface.op_At" ]
[]
true
false
true
false
false
let auto_unchanged_node_connections_list_unchanged h0 h1 d n =
assert (B.loc_disjoint (B.loc_buffer d) (DLL.dll_fp0 (d @ h0))); DLL.extract_nodelist_fp0 (as_list h0 d) ((as_list h0 d) `L.index_of` n); assert (B.loc_disjoint (B.loc_buffer d) (B.loc_buffer n))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.elements
val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m)
val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m)
let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 55, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> FStar.FiniteMap.Base.setfun_t a b (FStar.FiniteMap.Base.domain m)
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "FStar.FiniteMap.Base.domain" ]
[]
false
false
false
false
false
let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) =
let (| _ , f |) = m in f
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.map_as_list
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)})
let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m))
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 70, "start_col": 0, "start_line": 68 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> Prims.GTot (items: Prims.list (a * b) { FStar.FiniteMap.Base.item_list_doesnt_repeat_keys items /\ (forall (key: a). FStar.FiniteMap.Base.key_in_item_list key items <==> FStar.FiniteMap.Base.mem key m) } )
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.FiniteMap.Base.key_list_to_item_list", "FStar.FiniteSet.Base.set_as_list", "FStar.FiniteMap.Base.domain", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.b2t", "FStar.FiniteMap.Base.item_list_doesnt_repeat_keys", "Prims.l_Forall", "Prims.l_iff", "FStar.FiniteMap.Base.key_in_item_list", "FStar.FiniteMap.Base.mem" ]
[]
false
false
false
false
false
let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b) { item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m) }) =
key_list_to_item_list m (FSet.set_as_list (domain m))
false
Hacl.Impl.K256.PointAdd.fst
Hacl.Impl.K256.PointAdd.point_add_no_alloc
val point_add_no_alloc (out p q:point) (tmp:lbuffer uint64 (9ul *! nlimb)) : Stack unit (requires fun h -> live h out /\ live h p /\ live h q /\ live h tmp /\ eq_or_disjoint out p /\ eq_or_disjoint out q /\ eq_or_disjoint p q /\ disjoint p tmp /\ disjoint q tmp /\ disjoint out tmp /\ point_inv h p /\ point_inv h q) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_add (point_eval h0 p) (point_eval h0 q))
val point_add_no_alloc (out p q:point) (tmp:lbuffer uint64 (9ul *! nlimb)) : Stack unit (requires fun h -> live h out /\ live h p /\ live h q /\ live h tmp /\ eq_or_disjoint out p /\ eq_or_disjoint out q /\ eq_or_disjoint p q /\ disjoint p tmp /\ disjoint q tmp /\ disjoint out tmp /\ point_inv h p /\ point_inv h q) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_add (point_eval h0 p) (point_eval h0 q))
let point_add_no_alloc out p q tmp = let x1, y1, z1 = getx p, gety p, getz p in let x2, y2, z2 = getx q, gety q, getz q in let x3, y3, z3 = getx out, gety out, getz out in let xx = sub tmp 0ul nlimb in let yy = sub tmp nlimb nlimb in let zz = sub tmp (2ul *! nlimb) nlimb in let xy_pairs = sub tmp (3ul *! nlimb) nlimb in let yz_pairs = sub tmp (4ul *! nlimb) nlimb in let xz_pairs = sub tmp (5ul *! nlimb) nlimb in let yy_m_bzz3 = sub tmp (6ul *! nlimb) nlimb in let yy_p_bzz3 = sub tmp (7ul *! nlimb) nlimb in let tmp1 = sub tmp (8ul *! nlimb) nlimb in let h0 = ST.get () in fmul xx x1 x2; //xx = x1*x2 fmul yy y1 y2; //yy = y1*y2 fmul zz z1 z2; //zz = z1*z2 let h1 = ST.get () in // assert (inv_lazy_reduced2 h1 xx); // assert (inv_lazy_reduced2 h1 yy); // assert (inv_lazy_reduced2 h1 zz); point_add_xy_pairs x1 y1 x2 y2 xx yy tmp1 xy_pairs; //xy_pairs = (x1+y1)*(x2+y2)-(xx+yy) point_add_xy_pairs y1 z1 y2 z2 yy zz tmp1 yz_pairs; //yz_pairs = (y1+z1)*(y2+z2)-(yy+zz) point_add_xy_pairs x1 z1 x2 z2 xx zz tmp1 xz_pairs; //xz_pairs = (x1+z1)*(x2+z2)-(xx+zz) let h2 = ST.get () in // assert (felem_fits5 (as_felem5 h2 xy_pairs) (9,9,9,9,10)); // assert (felem_fits5 (as_felem5 h2 yz_pairs) (9,9,9,9,10)); // assert (felem_fits5 (as_felem5 h2 xz_pairs) (9,9,9,9,10)); yy_mp_bzz3 zz yy tmp1 yy_m_bzz3 yy_p_bzz3; fmul_3b_normalize_weak x3 yz_pairs; //x3 = byz3 = (3*b)*yz_pairs let h7 = ST.get () in // assert (felem_fits5 (as_felem5 h7 x3) (1,1,1,1,2)); fmul_small_num z3 xx (u64 3); //z3 = xx3 = 3*xx let h8 = ST.get () in BL.fmul15_lemma (1,1,1,1,2) 3 (as_felem5 h7 xx) (u64 3); // assert (felem_fits5 (as_felem5 h8 z3) (3,3,3,3,6)); fmul_3b_normalize_weak y3 z3; //y3 = bxx9 = (3*b)*xx3 let h9 = ST.get () in // assert (felem_fits5 (as_felem5 h9 y3) (1,1,1,1,2)); ab_minus_cd xy_pairs yy_m_bzz3 x3 xz_pairs tmp1; //x3 = (xy_pairs*yy_m_bzz3-byz3*xz_pairs) ab_plus_cd yy_p_bzz3 yy_m_bzz3 y3 xz_pairs tmp1; //y3 = (yy_p_bzz3*yy_m_bzz3+bxx9*xz_pairs) ab_plus_cd yz_pairs yy_p_bzz3 z3 xy_pairs tmp1
{ "file_name": "code/k256/Hacl.Impl.K256.PointAdd.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 226, "start_col": 0, "start_line": 174 }
module Hacl.Impl.K256.PointAdd open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module S = Spec.K256 module BL = Hacl.Spec.K256.Field52.Lemmas open Hacl.K256.Field open Hacl.Impl.K256.Point #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val point_add_xy_pairs (x1 y1 x2 y2 xx yy tmp xy_pairs:felem) : Stack unit (requires fun h -> live h x1 /\ live h y1 /\ live h x2 /\ live h y2 /\ live h xx /\ live h yy /\ live h tmp /\ live h xy_pairs /\ eq_or_disjoint x1 y1 /\ eq_or_disjoint x2 y2 /\ eq_or_disjoint xx yy /\ disjoint x1 xy_pairs /\ disjoint y1 xy_pairs /\ disjoint x2 xy_pairs /\ disjoint y2 xy_pairs /\ disjoint x1 tmp /\ disjoint y1 tmp /\ disjoint x2 tmp /\ disjoint y2 tmp /\ disjoint xx xy_pairs /\ disjoint yy xy_pairs /\ disjoint xx tmp /\ disjoint yy tmp /\ disjoint xy_pairs tmp /\ inv_lazy_reduced2 h x1 /\ inv_lazy_reduced2 h y1 /\ inv_lazy_reduced2 h x2 /\ inv_lazy_reduced2 h y2 /\ inv_lazy_reduced2 h xx /\ inv_lazy_reduced2 h yy) (ensures fun h0 _ h1 -> modifies (loc xy_pairs |+| loc tmp) h0 h1 /\ feval h1 xy_pairs = S.fsub (S.fmul (S.fadd (feval h0 x1) (feval h0 y1)) (S.fadd (feval h0 x2) (feval h0 y2))) (S.fadd (feval h0 xx) (feval h0 yy)) /\ felem_fits5 (as_felem5 h1 xy_pairs) (9,9,9,9,10)) let point_add_xy_pairs x1 y1 x2 y2 xx yy tmp xy_pairs = let h0 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h0 x1) (as_felem5 h0 y1); BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h0 x2) (as_felem5 h0 y2); fadd xy_pairs x1 y1; fadd tmp x2 y2; let h1 = ST.get () in assert (felem_fits5 (as_felem5 h1 xy_pairs) (2,2,2,2,4)); assert (felem_fits5 (as_felem5 h1 tmp) (2,2,2,2,4)); fmul xy_pairs xy_pairs tmp; let h2 = ST.get () in assert (felem_fits5 (as_felem5 h2 xy_pairs) (1,1,1,1,2)); BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h2 xx) (as_felem5 h2 yy); fadd tmp xx yy; let h3 = ST.get () in assert (felem_fits5 (as_felem5 h3 tmp) (2,2,2,2,4)); fsub xy_pairs xy_pairs tmp (u64 4); let h4 = ST.get () in BL.fsub5_lemma (1,1,1,1,2) (2,2,2,2,4) (as_felem5 h3 xy_pairs) (as_felem5 h3 tmp) (u64 4); assert (felem_fits5 (as_felem5 h4 xy_pairs) (9,9,9,9,10)) inline_for_extraction noextract val ab_plus_cd (a b c d tmp:felem) : Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ live h d /\ live h tmp /\ disjoint a b /\ disjoint c d /\ eq_or_disjoint a b /\ eq_or_disjoint a d /\ disjoint a tmp /\ disjoint b tmp /\ disjoint c tmp /\ disjoint d tmp /\ felem_fits5 (as_felem5 h a) (9,9,9,9,10) /\ felem_fits5 (as_felem5 h b) (5,5,5,5,6) /\ felem_fits5 (as_felem5 h c) (3,3,3,3,6) /\ felem_fits5 (as_felem5 h d) (9,9,9,9,10)) (ensures fun h0 _ h1 -> modifies (loc c |+| loc tmp) h0 h1 /\ feval h1 c == S.fadd (S.fmul (feval h0 a) (feval h0 b)) (S.fmul (feval h0 c) (feval h0 d)) /\ inv_lazy_reduced2 h1 c) let ab_plus_cd a b c d tmp = fmul tmp a b; fmul c c d; let h1 = ST.get () in assert (inv_lazy_reduced2 h1 tmp); assert (inv_lazy_reduced2 h1 c); BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 tmp) (as_felem5 h1 c); fadd c tmp c; let h2 = ST.get () in assert (felem_fits5 (as_felem5 h2 c) (2,2,2,2,4)); fnormalize_weak c c; BL.normalize_weak5_lemma (2,2,2,2,4) (as_felem5 h2 c) inline_for_extraction noextract val ab_minus_cd (a b c d tmp:felem) : Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ live h d /\ live h tmp /\ disjoint a b /\ disjoint c d /\ eq_or_disjoint a b /\ eq_or_disjoint a d /\ disjoint a tmp /\ disjoint b tmp /\ disjoint c tmp /\ disjoint d tmp /\ felem_fits5 (as_felem5 h a) (9,9,9,9,10) /\ felem_fits5 (as_felem5 h b) (5,5,5,5,6) /\ felem_fits5 (as_felem5 h c) (1,1,1,1,2) /\ felem_fits5 (as_felem5 h d) (9,9,9,9,10)) (ensures fun h0 _ h1 -> modifies (loc c |+| loc tmp) h0 h1 /\ feval h1 c == S.fsub (S.fmul (feval h0 a) (feval h0 b)) (S.fmul (feval h0 c) (feval h0 d)) /\ inv_lazy_reduced2 h1 c) let ab_minus_cd a b c d tmp = fmul tmp a b; fmul c c d; let h1 = ST.get () in assert (inv_lazy_reduced2 h1 tmp); assert (inv_lazy_reduced2 h1 c); BL.fsub5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 tmp) (as_felem5 h1 c) (u64 2); fsub c tmp c (u64 2); let h2 = ST.get () in assert (felem_fits5 (as_felem5 h2 c) (5,5,5,5,6)); fnormalize_weak c c; BL.normalize_weak5_lemma (5,5,5,5,6) (as_felem5 h2 c) inline_for_extraction noextract val yy_mp_bzz3 (zz yy tmp1 yy_m_bzz3 yy_p_bzz3:felem) : Stack unit (requires fun h -> live h zz /\ live h yy /\ live h tmp1 /\ live h yy_m_bzz3 /\ live h yy_p_bzz3 /\ disjoint zz yy /\ disjoint zz tmp1 /\ disjoint zz yy_m_bzz3 /\ disjoint zz yy_p_bzz3 /\ disjoint yy tmp1 /\ disjoint yy yy_m_bzz3 /\ disjoint yy yy_p_bzz3 /\ disjoint tmp1 yy_m_bzz3 /\ disjoint tmp1 yy_p_bzz3 /\ disjoint yy_m_bzz3 yy_p_bzz3 /\ inv_lazy_reduced2 h zz /\ inv_lazy_reduced2 h yy) (ensures fun h0 _ h1 -> modifies (loc tmp1 |+| loc yy_m_bzz3 |+| loc yy_p_bzz3) h0 h1 /\ (let bzz3 = S.fmul (S.fmul 3 S.b) (feval h0 zz) in feval h1 yy_m_bzz3 = S.fsub (feval h0 yy) bzz3 /\ feval h1 yy_p_bzz3 = S.fadd (feval h0 yy) bzz3 /\ felem_fits5 (as_felem5 h1 yy_m_bzz3) (5,5,5,5,6) /\ felem_fits5 (as_felem5 h1 yy_p_bzz3) (2,2,2,2,4))) let yy_mp_bzz3 zz yy tmp1 yy_m_bzz3 yy_p_bzz3 = fmul_3b_normalize_weak tmp1 zz; //tmp1 = bzz3 = (3*b)*zz let h1 = ST.get () in // assert (felem_fits5 (as_felem5 h1 tmp1) (1,1,1,1,2)); fsub yy_m_bzz3 yy tmp1 (u64 2); //yy_m_bzz3 = yy-bzz3 let h2 = ST.get () in BL.fsub5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 yy) (as_felem5 h1 tmp1) (u64 2); // assert (felem_fits5 (as_felem5 h5 yy_m_bzz3) (5,5,5,5,6)); fadd yy_p_bzz3 yy tmp1; //yy_p_bzz3 = yy+bzz3 let h3 = ST.get () in BL.fadd5_lemma (1,1,1,1,2) (1,1,1,1,2) (as_felem5 h1 yy) (as_felem5 h1 tmp1) // assert (felem_fits5 (as_felem5 h6 yy_p_bzz3) (2,2,2,2,4)); #set-options "--z3rlimit 300" inline_for_extraction noextract val point_add_no_alloc (out p q:point) (tmp:lbuffer uint64 (9ul *! nlimb)) : Stack unit (requires fun h -> live h out /\ live h p /\ live h q /\ live h tmp /\ eq_or_disjoint out p /\ eq_or_disjoint out q /\ eq_or_disjoint p q /\ disjoint p tmp /\ disjoint q tmp /\ disjoint out tmp /\ point_inv h p /\ point_inv h q) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ point_inv h1 out /\ point_eval h1 out == S.point_add (point_eval h0 p) (point_eval h0 q))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.K256.Field52.Lemmas.fsti.checked", "Hacl.K256.Field.fsti.checked", "Hacl.Impl.K256.Point.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.K256.PointAdd.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256.Field", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.K256.Field52.Lemmas", "short_module": "BL" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.K256.Point.point -> p: Hacl.Impl.K256.Point.point -> q: Hacl.Impl.K256.Point.point -> tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 (9ul *! Hacl.K256.Field.nlimb) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.K256.Point.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.K256.Field.nlimb", "Hacl.K256.Field.felem", "Hacl.Impl.K256.PointAdd.ab_plus_cd", "Prims.unit", "Hacl.Impl.K256.PointAdd.ab_minus_cd", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.K256.Field.fmul_3b_normalize_weak", "Hacl.Spec.K256.Field52.Lemmas.fmul15_lemma", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Hacl.K256.Field.as_felem5", "Lib.IntTypes.u64", "Hacl.K256.Field.fmul_small_num", "Hacl.Impl.K256.PointAdd.yy_mp_bzz3", "Hacl.Impl.K256.PointAdd.point_add_xy_pairs", "Hacl.K256.Field.fmul", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.Mktuple3", "Hacl.Impl.K256.Point.getz", "Hacl.Impl.K256.Point.gety", "Hacl.Impl.K256.Point.getx" ]
[]
false
true
false
false
false
let point_add_no_alloc out p q tmp =
let x1, y1, z1 = getx p, gety p, getz p in let x2, y2, z2 = getx q, gety q, getz q in let x3, y3, z3 = getx out, gety out, getz out in let xx = sub tmp 0ul nlimb in let yy = sub tmp nlimb nlimb in let zz = sub tmp (2ul *! nlimb) nlimb in let xy_pairs = sub tmp (3ul *! nlimb) nlimb in let yz_pairs = sub tmp (4ul *! nlimb) nlimb in let xz_pairs = sub tmp (5ul *! nlimb) nlimb in let yy_m_bzz3 = sub tmp (6ul *! nlimb) nlimb in let yy_p_bzz3 = sub tmp (7ul *! nlimb) nlimb in let tmp1 = sub tmp (8ul *! nlimb) nlimb in let h0 = ST.get () in fmul xx x1 x2; fmul yy y1 y2; fmul zz z1 z2; let h1 = ST.get () in point_add_xy_pairs x1 y1 x2 y2 xx yy tmp1 xy_pairs; point_add_xy_pairs y1 z1 y2 z2 yy zz tmp1 yz_pairs; point_add_xy_pairs x1 z1 x2 z2 xx zz tmp1 xz_pairs; let h2 = ST.get () in yy_mp_bzz3 zz yy tmp1 yy_m_bzz3 yy_p_bzz3; fmul_3b_normalize_weak x3 yz_pairs; let h7 = ST.get () in fmul_small_num z3 xx (u64 3); let h8 = ST.get () in BL.fmul15_lemma (1, 1, 1, 1, 2) 3 (as_felem5 h7 xx) (u64 3); fmul_3b_normalize_weak y3 z3; let h9 = ST.get () in ab_minus_cd xy_pairs yy_m_bzz3 x3 xz_pairs tmp1; ab_plus_cd yy_p_bzz3 yy_m_bzz3 y3 xz_pairs tmp1; ab_plus_cd yz_pairs yy_p_bzz3 z3 xy_pairs tmp1
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.emptymap
val emptymap (#a: eqtype) (#b: Type u#b) : map a b
val emptymap (#a: eqtype) (#b: Type u#b) : map a b
let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 98, "start_col": 0, "start_line": 97 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.FiniteMap.Base.map a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Prims.Mkdtuple2", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "FStar.FiniteSet.Base.emptyset", "FStar.FunctionalExtensionality.on_domain", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.None", "FStar.FiniteMap.Base.map" ]
[]
false
false
false
false
false
let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) =
(| FSet.emptyset, on_domain a (fun key -> None) |)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.key_list_to_item_list
val key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a { FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m)) }) : GTot (items: list (a * b) { item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items) }) (decreases keys)
val key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a { FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m)) }) : GTot (items: list (a * b) { item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items) }) (decreases keys)
let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 104, "end_line": 66, "start_col": 0, "start_line": 57 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> keys: Prims.list a { FStar.FiniteSet.Base.list_nonrepeating keys /\ (forall (key: a). FStar.List.Tot.Base.mem key keys ==> FStar.FiniteSet.Base.mem key (FStar.FiniteMap.Base.domain m)) } -> Prims.GTot (items: Prims.list (a * b) { FStar.FiniteMap.Base.item_list_doesnt_repeat_keys items /\ (forall (key: a). FStar.List.Tot.Base.mem key keys <==> FStar.FiniteMap.Base.key_in_item_list key items) })
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.list", "Prims.l_and", "Prims.b2t", "FStar.FiniteSet.Base.list_nonrepeating", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.mem", "FStar.FiniteSet.Base.mem", "FStar.FiniteMap.Base.domain", "Prims.Nil", "FStar.Pervasives.Native.tuple2", "Prims.Cons", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.FiniteMap.Base.elements", "FStar.FiniteMap.Base.key_list_to_item_list", "FStar.FiniteMap.Base.item_list_doesnt_repeat_keys", "Prims.l_iff", "FStar.FiniteMap.Base.key_in_item_list" ]
[ "recursion" ]
false
false
false
false
false
let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a { FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m)) }) : GTot (items: list (a * b) { item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items) }) (decreases keys) =
match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.merge
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b
val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b
let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 123, "start_col": 0, "start_line": 120 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m1: FStar.FiniteMap.Base.map a b -> m2: FStar.FiniteMap.Base.map a b -> FStar.FiniteMap.Base.map a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.Mkdtuple2", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "FStar.Pervasives.Native.option", "FStar.FunctionalExtensionality.on_domain", "FStar.FiniteSet.Base.mem", "FStar.FiniteMap.Base.domain", "FStar.FiniteMap.Base.elements", "Prims.bool", "FStar.FiniteSet.Base.union" ]
[]
false
false
false
false
false
let merge (#a: eqtype) (#b: Type u#b) (m1 m2: map a b) : map a b =
let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.choose
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m})
val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m})
let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 153, "start_col": 0, "start_line": 152 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b {exists (key: a). FStar.FiniteMap.Base.mem key m} -> Prims.GTot (key: a{FStar.FiniteMap.Base.mem key m})
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.l_Exists", "Prims.b2t", "FStar.FiniteMap.Base.mem", "FStar.FiniteSet.Base.choose", "FStar.FiniteMap.Base.domain" ]
[]
false
false
false
false
false
let choose (#a: eqtype) (#b: Type u#b) (m: map a b {exists key. mem key m}) : GTot (key: a{mem key m}) =
FSet.choose (domain m)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.subtract
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b
val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b
let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 132, "start_col": 0, "start_line": 129 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.FiniteMap.Base.map a b -> s: FStar.FiniteSet.Base.set a -> FStar.FiniteMap.Base.map a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "FStar.FiniteSet.Base.set", "Prims.Mkdtuple2", "FStar.FiniteMap.Base.setfun_t", "FStar.Pervasives.Native.option", "FStar.FunctionalExtensionality.on_domain", "FStar.FiniteSet.Base.mem", "FStar.FiniteMap.Base.elements", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.FiniteSet.Base.difference", "FStar.FiniteMap.Base.domain" ]
[]
false
false
false
false
false
let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b =
let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |)
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.empty_or_domain_occupied_lemma
val empty_or_domain_occupied_lemma: Prims.unit -> Lemma (empty_or_domain_occupied_fact u#b)
val empty_or_domain_occupied_lemma: Prims.unit -> Lemma (empty_or_domain_occupied_fact u#b)
let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () )
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 180, "start_col": 0, "start_line": 167 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.empty_or_domain_occupied_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteMap.Base.map", "Prims.l_or", "Prims.eq2", "FStar.FiniteMap.Base.emptymap", "Prims.l_Exists", "Prims.b2t", "FStar.FiniteMap.Base.mem", "Prims.op_Equality", "Prims.int", "FStar.FiniteSet.Base.cardinality", "FStar.FiniteMap.Base.domain", "FStar.Classical.Sugar.or_intro_left", "Prims.squash", "Prims.l_not", "FStar.FiniteMap.Base.cardinality_zero_iff_empty_lemma", "Prims._assert", "FStar.FiniteMap.Base.cardinality", "Prims.bool", "FStar.Classical.Sugar.or_intro_right", "Prims.l_True", "FStar.FiniteMap.Base.empty_or_domain_occupied_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) =
introduce forall (a: eqtype) (b: Type u#b) (m: map a b) . m == emptymap \/ (exists k. mem k m) with (if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left (assert (cardinality m = 0); cardinality_zero_iff_empty_lemma ()) else introduce m == emptymap \/ (exists k. mem k m) with Right ())
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.insert
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b
val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b
let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |)
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 114, "start_col": 0, "start_line": 111 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V;
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: a -> v: b -> m: FStar.FiniteMap.Base.map a b -> FStar.FiniteMap.Base.map a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.Mkdtuple2", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "FStar.Pervasives.Native.option", "FStar.FunctionalExtensionality.on_domain", "Prims.op_Equality", "FStar.Pervasives.Native.Some", "Prims.bool", "FStar.FiniteMap.Base.elements", "FStar.FiniteSet.Base.insert", "FStar.FiniteMap.Base.domain" ]
[]
false
false
false
false
false
let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b =
let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.auto_unchanged_node_connections_dll_valid
val auto_unchanged_node_connections_dll_valid (h0 h1:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d /\ B.modifies (fp_node n) h0 h1 /\ unchanged_node_connections h0 h1 n)) (ensures (dll_valid h1 d)) [SMTPat (dll_valid h1 d); SMTPat (B.modifies (fp_node n) h0 h1); SMTPat (unchanged_node_connections h0 h1 n)]
val auto_unchanged_node_connections_dll_valid (h0 h1:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h0 d /\ n `L.memP` as_list h0 d /\ B.modifies (fp_node n) h0 h1 /\ unchanged_node_connections h0 h1 n)) (ensures (dll_valid h1 d)) [SMTPat (dll_valid h1 d); SMTPat (B.modifies (fp_node n) h0 h1); SMTPat (unchanged_node_connections h0 h1 n)]
let auto_unchanged_node_connections_dll_valid h0 h1 d (n:node 'a) = DLL.extract_nodelist_fp0 (as_list h0 d) (as_list h0 d `L.index_of` n); assert (d@h0 == d@h1); assert (as_list h0 d == as_list h1 d); let rec aux1 #nl' (nl:list (node 'a)) : Lemma (requires ( (B.modifies (B.loc_buffer n) h0 h1) /\ (DLL.nodelist_contained h0 nl) /\ (DLL.nodelist_aa_r nl) /\ (nl' `L.append` nl == as_list h1 d) /\ (n `L.memP` nl \/ B.loc_buffer n `B.loc_disjoint` DLL.nodelist_fp0 nl))) (ensures (DLL.nodelist_contained h1 nl)) (decreases (L.length nl)) = match nl with | [] -> () | x :: xs -> let nl1', nl1 = L.snoc (nl', x), xs in L.append_l_cons x xs nl'; aux1 #nl1' nl1 in aux1 #[] (as_list h1 d); assert (DLL.nodelist_contained h1 (as_list h1 d)); assert ((d@h1).DLL.lhead =!= B.null); assert ((d@h1).DLL.ltail =!= B.null); let rec aux2 #nl' (nl:list (node 'a)) : Lemma (requires ( (B.modifies (B.loc_buffer n) h0 h1) /\ unchanged_node_connections h0 h1 n /\ (DLL.nodelist_contained h0 nl) /\ (DLL.nodelist_contained h1 nl) /\ (DLL.nodelist_conn h0 nl) /\ (DLL.nodelist_aa_r nl) /\ (nl' `L.append` nl == as_list h1 d) /\ (n `L.memP` nl \/ B.loc_buffer n `B.loc_disjoint` DLL.nodelist_fp0 nl))) (ensures (DLL.nodelist_conn h1 nl)) (decreases (L.length nl)) = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> let nl1', nl1 = L.snoc (nl', n1), rest in L.append_l_cons n1 rest nl'; aux2 #nl1' nl1; assert (DLL.nodelist_conn h1 rest); FStar.Classical.arrow_to_impl #(n `L.memP` rest) #((n1@h1).DLL.flink == (n1@h0).DLL.flink) (fun _ -> DLL.extract_nodelist_fp0 rest (rest `L.index_of` n)); FStar.Classical.arrow_to_impl #(n `L.memP` ns) #((n2@h1).DLL.blink == (n2@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_fp0 ns (ns `L.index_of` n)) in aux2 #[] (as_list h1 d); assert (DLL.nodelist_conn h1 (as_list h1 d)); FStar.Classical.arrow_to_impl #((d@h1).DLL.lhead =!= n) #(((d@h1).DLL.lhead@h1).DLL.blink == B.null) (fun _ -> let l = L.tl (as_list h1 d) in DLL.extract_nodelist_fp0 l (l `L.index_of` n)); L.lemma_unsnoc_is_last (as_list h1 d); FStar.Classical.arrow_to_impl #((d@h1).DLL.ltail =!= n) #(((d@h1).DLL.ltail@h1).DLL.flink == B.null) (fun _ -> let l, _ = L.unsnoc (as_list h1 d) in let i = as_list h1 d `L.index_of` n in assert (i < L.length (as_list h1 d)); assert (i = L.length (as_list h1 d) ==> (d@h1).DLL.ltail == n); assert ((d@h1).DLL.ltail =!= n); assert (i < L.length (as_list h1 d) - 1); L.lemma_unsnoc_length (as_list h1 d); L.lemma_unsnoc_index (as_list h1 d) i; DLL.extract_nodelist_fp0 l (l `L.index_of` n))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 1025, "start_col": 0, "start_line": 955 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n] #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_before #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_before (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.lhead)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (d@h0).DLL.ltail)); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; // assert (n' `L.memP` as_list h1 d); _lemma_prev_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.blink =!= B.null) #((n'@h0).DLL.blink =!= B.null /\ (n'@h0).DLL.blink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.blink); // assert ((n'@h0).DLL.blink =!= B.null ==> (n'@h0).DLL.blink `L.memP` as_list h1 d); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.blink (as_list h1 d); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer n')); // assert (fp_dll h1 d `B.loc_includes` (B.loc_buffer (n'@h0).DLL.blink)); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in _lemma_split_using_splitAt (as_list h00 d) n'; _lemma_append_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (as_list h00 d); _lemma_length_g_node_vals h00 (as_list h00 d); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); // assert ((as_list h00 d `L.index_of` n') < L.length (g_node_vals h00 (as_list h00 d))); _lemma_insertion_maintains_unchanged_node_vals h0 h1 (as_list h0 d) (as_list h1 d) n' n; // assert (unchanged_node_vals h0 h1 (as_list h0 d)); _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h00 d); // assert (g_node_vals h11 (as_list h00 d) == g_node_vals h00 (as_list h00 d)); // assert ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in // let m1, m2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // g_node_vals h11 // (l1 `L.append` l2) == (m1 `L.append` m2) /\ L.length l1 = L.length m1); L.lemma_splitAt_append (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)); _lemma_length_g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d))); L.append_length_inv_head (g_node_vals h11 (fst (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (g_node_vals h11 (snd (L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d)))) (fst (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))) (snd (L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)))); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_list h00 d) in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1)); // assert (g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l2) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l2)); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n; // assert (n `L.memP` as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); // assert (g_node_val h1 n == g_node_val h0 n); _lemma_append_g_node_vals h11 (let l1, l2 = L.split_using (as_list h00 d) n' in l1) (let l1, l2 = L.split_using (as_list h00 d) n' in (n :: l2)); // assert (g_node_vals h11 ( // let l1, l2 = L.split_using (as_list h00 d) n' in // l1 `L.append` (n :: l2)) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (l_insert_before n' (as_list h00 d) n) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (g_node_vals h11 (as_list h11 d) == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (g_node_vals h00 (as_list h00 d)) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == ( // let l1, l2 = L.splitAt (as_list h00 d `L.index_of` n') (as_payload_list h00 d) in // l1 `L.append` ((g_node_val h00 n) :: l2))); // assert (as_payload_list h11 d == l_insert_before' // (as_list h00 d `L.index_of` n') (as_payload_list h00 d) (g_node_val h00 n)); () #reset-options #set-options "--z3rlimit 80 --max_fuel 2 --max_ifuel 1" let dll_insert_after #t n' d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_after (!*d) n' n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n n'; _lemma_next_node_in_list h0 n' d; FStar.Classical.arrow_to_impl #((n'@h0).DLL.flink =!= B.null) #((n'@h0).DLL.flink =!= B.null /\ (n'@h0).DLL.flink `L.memP` as_list h1 d) (fun _ -> _lemma_insertion_maintains_memP (as_list h0 d) (as_list h1 d) n' n (n'@h0).DLL.flink); _lemma_node_in_list_is_included n' (as_list h1 d); _lemma_node_in_list_or_null_is_included (n'@h0).DLL.flink (as_list h1 d); // assert (B.modifies (fp_dll h1 d) h0 h1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_head #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_head (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_tail #t d = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_tail (!*d) in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1" let dll_remove_mid #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_remove_node (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in FStar.Classical.arrow_to_impl #(L.length (d@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d@h0).DLL.nodes (L.length (d@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d@h0).DLL.nodes); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.lhead@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer ((d@h0).DLL.ltail@h0).DLL.blink); _lemma_next_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.flink) (d@h0).DLL.nodes; _lemma_prev_node_in_list h0 n d; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d@h0).DLL.nodes; // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.flink); // assert (DLL.dll_fp0 (d@h0) `B.loc_includes` B.loc_buffer (n@h0).DLL.blink); _lemma_unchanged_node_vals_stays_valid0 h' h1 d; _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h0 d); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_append #t d1 d2 = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_append (!*d1) (!*d2) in let h' = HST.get () in d1 *= y; let h1 = HST.get () in DLL.nodelist_append_fp0 (as_list h0 d1) (as_list h0 d2); assert (_pred_nl_disjoint h0 (as_list h1 d1)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d1); HST.pop_frame (); let h11 = HST.get () in admit () (* Due to recent "double ghost" change *) #reset-options #set-options "--z3rlimit 100 --max_fuel 2 --max_ifuel 1" let dll_split_using #t d1 d2 n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y1, y2 = DLL.dll_split_using (!*d1) n in let h0' = HST.get () in d1 *= y1; let h0'' = HST.get () in d2 *= y2; let h1 = HST.get () in assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0)); assert (DLL.dll_fp0 (d1@h0) `B.loc_includes` DLL.dll_fp0 y1); FStar.Classical.arrow_to_impl #(L.length (d1@h0).DLL.nodes >= 2) #(DLL.dll_fp0 (d1@h0) `B.loc_includes` B.loc_buffer ((d1@h0).DLL.ltail@h0).DLL.blink) (fun _ -> DLL.extract_nodelist_conn h0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); DLL.extract_nodelist_fp0 (d1@h0).DLL.nodes (L.length (d1@h0).DLL.nodes - 2); L.lemma_unsnoc_is_last (d1@h0).DLL.nodes); _lemma_prev_node_in_list h0 n d1; _lemma_node_in_list_or_null_is_included ((n@h0).DLL.blink) (d1@h0).DLL.nodes; _lemma_node_in_list_is_included n (d1@h0).DLL.nodes; assert (B.loc_buffer d1 `B.loc_disjoint` DLL.dll_fp0 (d1@h0')); _lemma_unchanged_node_vals_stays_valid0 h0' h0'' d1; _lemma_unchanged_node_vals_transitive h0 h0' h0'' (as_list h0 d1); // _lemma_unchanged_node_vals_when_disjoint h0'' h1 (B.loc_buffer d2) (as_list h0 d1); assert (unchanged_node_vals h0'' h1 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h0 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d1)); assert (_pred_nl_disjoint h0 (as_list h1 d2)); _lemma_unchanged_node_vals_transitive h0 h0'' h1 (as_list h0 d1); assert (dll_valid h0'' d1); _lemma_nodelist_conn_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); _lemma_nodelist_contained_in_unmodified_mem h0'' h1 (B.loc_buffer d2) (as_list h0'' d1); assert (dll_valid h1 d1); _lemma_nodelist_conn_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0' h0'' (B.loc_buffer d1) y2.DLL.nodes; assert (DLL.dll_valid h0'' y2); assert (dll_valid h1 d2); HST.pop_frame (); let h11 = HST.get () in B.popped_modifies h1 h11; let loc = B.loc_region_only false (HS.get_tip h1) in _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_contained_in_unmodified_mem h1 h11 loc (as_list h11 d2); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d1); _lemma_nodelist_conn_in_unmodified_mem h1 h11 loc (as_list h11 d2); admit () (* Due to recent "double ghost" change *) #reset-options /// Automatic validity maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_remains_valid_upon_staying_unchanged h0 h1 l d = _lemma_nodelist_contained_in_unmodified_mem h0 h1 l (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 l (as_list h1 d) let auto_node_remains_valid_upon_staying_unchanged h0 h1 l n = () let auto_node_remains_unchanged_upon_staying_unchanged_val h0 h1 n = () /// Automatic footprint maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_fp_upon_staying_unchanged h0 h1 l d = () /// Automatic value maintenance /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_dll_as_list_staying_unchanged h0 h1 l d =() let auto_dll_as_payload_list_staying_unchanged h0 h1 loc d = let rec aux loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_contained h0 nl /\ B.loc_disjoint (DLL.nodelist_fp0 nl) loc)) (ensures (g_node_vals h0 nl == g_node_vals h1 nl)) = match nl with | [] -> () | hd :: tl -> aux loc tl in aux loc (as_list h1 d) let auto_node_val_staying_unchanged h0 h1 l n = () /// Properties of nodes inside and outside lists /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_node_in_list_is_included h0 n d = _lemma_node_in_list_is_included n (as_list h0 d) let auto_node_in_list_is_valid h0 n d = DLL.extract_nodelist_contained h0 (as_list h0 d) (as_list h0 d `L.index_of` n) /// Properties related to unchanged connections /// /// These are lemmas that you shouldn't really need to refer to /// manually. If you do, it is (likely) a bug wrt the patterns, and /// you should ask someone who knows about how this library works to /// look at things. let auto_unchanged_node_connections_list_unchanged h0 h1 d n = assert (B.loc_disjoint (B.loc_buffer d) (DLL.dll_fp0 (d@h0))); DLL.extract_nodelist_fp0 (as_list h0 d) (as_list h0 d `L.index_of` n); assert (B.loc_disjoint (B.loc_buffer d) (B.loc_buffer n)) #set-options "--z3rlimit 10"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> FStar.Pervasives.Lemma (requires DoublyLinkedListIface.dll_valid h0 d /\ FStar.List.Tot.Base.memP n (DoublyLinkedListIface.as_list h0 d) /\ LowStar.Monotonic.Buffer.modifies (DoublyLinkedListIface.fp_node n) h0 h1 /\ DoublyLinkedListIface.unchanged_node_connections h0 h1 n) (ensures DoublyLinkedListIface.dll_valid h1 d) [ SMTPat (DoublyLinkedListIface.dll_valid h1 d); SMTPat (LowStar.Monotonic.Buffer.modifies (DoublyLinkedListIface.fp_node n) h0 h1); SMTPat (DoublyLinkedListIface.unchanged_node_connections h0 h1 n) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "FStar.Classical.arrow_to_impl", "Prims.l_not", "Prims.eq2", "LowStar.Buffer.buffer", "DoublyLinkedList.node", "Prims.l_or", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.g_is_null", "Prims.l_True", "Prims.bool", "Prims.logical", "DoublyLinkedList.__proj__Mkdll__item__ltail", "DoublyLinkedListIface.op_At", "DoublyLinkedList.dll", "DoublyLinkedList.__proj__Mknode__item__flink", "LowStar.Buffer.null", "Prims.squash", "Prims.list", "DoublyLinkedList.extract_nodelist_fp0", "FStar.List.Tot.Properties.index_of", "Prims.unit", "FStar.List.Tot.Properties.lemma_unsnoc_index", "DoublyLinkedListIface.as_list", "FStar.List.Tot.Properties.lemma_unsnoc_length", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "FStar.List.Tot.Base.length", "Prims.l_imp", "Prims.op_Equality", "Prims.nat", "Prims.l_and", "FStar.List.Tot.Base.index", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.unsnoc", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedList.__proj__Mkdll__item__lhead", "DoublyLinkedList.__proj__Mknode__item__blink", "FStar.List.Tot.Base.tl", "DoublyLinkedList.nodelist_conn", "Prims.Nil", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedListIface.unchanged_node_connections", "DoublyLinkedList.nodelist_contained", "DoublyLinkedList.nodelist_aa_r", "FStar.List.Tot.Base.append", "FStar.List.Tot.Base.memP", "LowStar.Monotonic.Buffer.loc_disjoint", "DoublyLinkedList.nodelist_fp0", "FStar.Pervasives.pattern", "Prims.precedes", "LowStar.Buffer.pointer_or_null", "FStar.List.Tot.Properties.append_l_cons", "FStar.Pervasives.Native.Mktuple2", "FStar.List.Tot.Base.snoc" ]
[]
false
false
true
false
false
let auto_unchanged_node_connections_dll_valid h0 h1 d (n: node 'a) =
DLL.extract_nodelist_fp0 (as_list h0 d) ((as_list h0 d) `L.index_of` n); assert (d @ h0 == d @ h1); assert (as_list h0 d == as_list h1 d); let rec aux1 #nl' (nl: list (node 'a)) : Lemma (requires ((B.modifies (B.loc_buffer n) h0 h1) /\ (DLL.nodelist_contained h0 nl) /\ (DLL.nodelist_aa_r nl) /\ (nl' `L.append` nl == as_list h1 d) /\ (n `L.memP` nl \/ (B.loc_buffer n) `B.loc_disjoint` (DLL.nodelist_fp0 nl)))) (ensures (DLL.nodelist_contained h1 nl)) (decreases (L.length nl)) = match nl with | [] -> () | x :: xs -> let nl1', nl1 = L.snoc (nl', x), xs in L.append_l_cons x xs nl'; aux1 #nl1' nl1 in aux1 #[] (as_list h1 d); assert (DLL.nodelist_contained h1 (as_list h1 d)); assert ((d @ h1).DLL.lhead =!= B.null); assert ((d @ h1).DLL.ltail =!= B.null); let rec aux2 #nl' (nl: list (node 'a)) : Lemma (requires ((B.modifies (B.loc_buffer n) h0 h1) /\ unchanged_node_connections h0 h1 n /\ (DLL.nodelist_contained h0 nl) /\ (DLL.nodelist_contained h1 nl) /\ (DLL.nodelist_conn h0 nl) /\ (DLL.nodelist_aa_r nl) /\ (nl' `L.append` nl == as_list h1 d) /\ (n `L.memP` nl \/ (B.loc_buffer n) `B.loc_disjoint` (DLL.nodelist_fp0 nl)))) (ensures (DLL.nodelist_conn h1 nl)) (decreases (L.length nl)) = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> let nl1', nl1 = L.snoc (nl', n1), rest in L.append_l_cons n1 rest nl'; aux2 #nl1' nl1; assert (DLL.nodelist_conn h1 rest); FStar.Classical.arrow_to_impl #(n `L.memP` rest) #((n1 @ h1).DLL.flink == (n1 @ h0).DLL.flink) (fun _ -> DLL.extract_nodelist_fp0 rest (rest `L.index_of` n)); FStar.Classical.arrow_to_impl #(n `L.memP` ns) #((n2 @ h1).DLL.blink == (n2 @ h0).DLL.blink) (fun _ -> DLL.extract_nodelist_fp0 ns (ns `L.index_of` n)) in aux2 #[] (as_list h1 d); assert (DLL.nodelist_conn h1 (as_list h1 d)); FStar.Classical.arrow_to_impl #((d @ h1).DLL.lhead =!= n) #(((d @ h1).DLL.lhead @ h1).DLL.blink == B.null) (fun _ -> let l = L.tl (as_list h1 d) in DLL.extract_nodelist_fp0 l (l `L.index_of` n)); L.lemma_unsnoc_is_last (as_list h1 d); FStar.Classical.arrow_to_impl #((d @ h1).DLL.ltail =!= n) #(((d @ h1).DLL.ltail @ h1).DLL.flink == B.null) (fun _ -> let l, _ = L.unsnoc (as_list h1 d) in let i = (as_list h1 d) `L.index_of` n in assert (i < L.length (as_list h1 d)); assert (i = L.length (as_list h1 d) ==> (d @ h1).DLL.ltail == n); assert ((d @ h1).DLL.ltail =!= n); assert (i < L.length (as_list h1 d) - 1); L.lemma_unsnoc_length (as_list h1 d); L.lemma_unsnoc_index (as_list h1 d) i; DLL.extract_nodelist_fp0 l (l `L.index_of` n))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.map_equal_lemma
val map_equal_lemma: Prims.unit -> Lemma (map_equal_fact u#b)
val map_equal_lemma: Prims.unit -> Lemma (map_equal_fact u#b)
let map_equal_lemma () : Lemma (map_equal_fact u#b) //Surprising; needed to split this goal into two = assert (map_equal_fact u#b) by (T.norm [delta_only [`%map_equal_fact]]; let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in T.split (); T.smt(); T.smt())
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 282, "start_col": 0, "start_line": 272 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) ) let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () ) let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists v. (values m) v) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v) ) let empty_or_items_occupied_lemma () : Lemma (empty_or_items_occupied_fact u#b) = introduce forall (a: eqtype) (b: Type u#b) (m: map a b). m == emptymap \/ (exists item. (items m) item) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists item. (items m) item) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((items m) (k, v)) ) let map_cardinality_matches_domain_lemma () : Lemma (map_cardinality_matches_domain_fact u#b) = () let values_contains_lemma () : Lemma (values_contains_fact u#b) = () let items_contains_lemma () : Lemma (items_contains_fact u#b) = () let empty_domain_empty_lemma () : Lemma (empty_domain_empty_fact u#b) = () let glue_domain_lemma () : Lemma (glue_domain_fact u#b) = () let glue_elements_lemma () : Lemma (glue_elements_fact u#b) = () let insert_elements_lemma () : Lemma (insert_elements_fact u#b) = () let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact u#b) = () let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact u#b) = () let merge_domain_is_union_lemma () : Lemma (merge_domain_is_union_fact u#b) = () let merge_element_lemma () : Lemma (merge_element_fact u#b) = () let subtract_domain_lemma () : Lemma (subtract_domain_fact u#b) = () let subtract_element_lemma () : Lemma (subtract_element_fact u#b) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.map_equal_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "FStar.FiniteMap.Base.map_equal_fact", "FStar.Tactics.V2.Derived.smt", "FStar.Tactics.V2.Logic.split", "FStar.Tactics.NamedView.binding", "FStar.Tactics.V2.Logic.forall_intro", "FStar.Stubs.Tactics.V2.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Prims.l_True", "Prims.squash", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let map_equal_lemma () : Lemma (map_equal_fact u#b) =
FStar.Tactics.Effect.assert_by_tactic (map_equal_fact u#b) (fun _ -> (); (T.norm [delta_only [`%map_equal_fact]]; let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in T.split (); T.smt (); T.smt ()))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.all_finite_map_facts_lemma
val all_finite_map_facts_lemma (_:unit) : Lemma (all_finite_map_facts u#b)
val all_finite_map_facts_lemma (_:unit) : Lemma (all_finite_map_facts u#b)
let all_finite_map_facts_lemma (_:unit) : Lemma (all_finite_map_facts u#b) = cardinality_zero_iff_empty_lemma u#b (); empty_or_domain_occupied_lemma u#b (); empty_or_values_occupied_lemma u#b (); empty_or_items_occupied_lemma u#b (); map_cardinality_matches_domain_lemma u#b (); values_contains_lemma u#b (); items_contains_lemma u#b (); empty_domain_empty_lemma u#b (); glue_domain_lemma u#b (); glue_elements_lemma u#b (); insert_elements_lemma u#b (); insert_member_cardinality_lemma u#b (); insert_nonmember_cardinality_lemma u#b (); merge_domain_is_union_lemma u#b (); merge_element_lemma u#b (); subtract_domain_lemma u#b (); subtract_element_lemma u#b (); map_equal_lemma u#b (); map_extensionality_lemma u#b (); disjoint_lemma u#b ()
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 321, "start_col": 0, "start_line": 300 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) ) let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () ) let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists v. (values m) v) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v) ) let empty_or_items_occupied_lemma () : Lemma (empty_or_items_occupied_fact u#b) = introduce forall (a: eqtype) (b: Type u#b) (m: map a b). m == emptymap \/ (exists item. (items m) item) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists item. (items m) item) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((items m) (k, v)) ) let map_cardinality_matches_domain_lemma () : Lemma (map_cardinality_matches_domain_fact u#b) = () let values_contains_lemma () : Lemma (values_contains_fact u#b) = () let items_contains_lemma () : Lemma (items_contains_fact u#b) = () let empty_domain_empty_lemma () : Lemma (empty_domain_empty_fact u#b) = () let glue_domain_lemma () : Lemma (glue_domain_fact u#b) = () let glue_elements_lemma () : Lemma (glue_elements_fact u#b) = () let insert_elements_lemma () : Lemma (insert_elements_fact u#b) = () let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact u#b) = () let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact u#b) = () let merge_domain_is_union_lemma () : Lemma (merge_domain_is_union_fact u#b) = () let merge_element_lemma () : Lemma (merge_element_fact u#b) = () let subtract_domain_lemma () : Lemma (subtract_domain_fact u#b) = () let subtract_element_lemma () : Lemma (subtract_element_fact u#b) = () let map_equal_lemma () : Lemma (map_equal_fact u#b) //Surprising; needed to split this goal into two = assert (map_equal_fact u#b) by (T.norm [delta_only [`%map_equal_fact]]; let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in T.split (); T.smt(); T.smt()) let map_extensionality_lemma () : Lemma (map_extensionality_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m1: map a b) (m2: map a b). equal m1 m2 ==> m1 == m2 with ( introduce equal m1 m2 ==> m1 == m2 with _. ( assert (FSet.equal (domain m1) (domain m2)); assert (feq (elements m1) (elements m2)) ) ) let disjoint_lemma () : Lemma (disjoint_fact u#b) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.all_finite_map_facts)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.FiniteMap.Base.disjoint_lemma", "FStar.FiniteMap.Base.map_extensionality_lemma", "FStar.FiniteMap.Base.map_equal_lemma", "FStar.FiniteMap.Base.subtract_element_lemma", "FStar.FiniteMap.Base.subtract_domain_lemma", "FStar.FiniteMap.Base.merge_element_lemma", "FStar.FiniteMap.Base.merge_domain_is_union_lemma", "FStar.FiniteMap.Base.insert_nonmember_cardinality_lemma", "FStar.FiniteMap.Base.insert_member_cardinality_lemma", "FStar.FiniteMap.Base.insert_elements_lemma", "FStar.FiniteMap.Base.glue_elements_lemma", "FStar.FiniteMap.Base.glue_domain_lemma", "FStar.FiniteMap.Base.empty_domain_empty_lemma", "FStar.FiniteMap.Base.items_contains_lemma", "FStar.FiniteMap.Base.values_contains_lemma", "FStar.FiniteMap.Base.map_cardinality_matches_domain_lemma", "FStar.FiniteMap.Base.empty_or_items_occupied_lemma", "FStar.FiniteMap.Base.empty_or_values_occupied_lemma", "FStar.FiniteMap.Base.empty_or_domain_occupied_lemma", "FStar.FiniteMap.Base.cardinality_zero_iff_empty_lemma", "Prims.l_True", "Prims.squash", "FStar.FiniteMap.Base.all_finite_map_facts", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let all_finite_map_facts_lemma (_: unit) : Lemma (all_finite_map_facts u#b) =
cardinality_zero_iff_empty_lemma u#b (); empty_or_domain_occupied_lemma u#b (); empty_or_values_occupied_lemma u#b (); empty_or_items_occupied_lemma u#b (); map_cardinality_matches_domain_lemma u#b (); values_contains_lemma u#b (); items_contains_lemma u#b (); empty_domain_empty_lemma u#b (); glue_domain_lemma u#b (); glue_elements_lemma u#b (); insert_elements_lemma u#b (); insert_member_cardinality_lemma u#b (); insert_nonmember_cardinality_lemma u#b (); merge_domain_is_union_lemma u#b (); merge_element_lemma u#b (); subtract_domain_lemma u#b (); subtract_element_lemma u#b (); map_equal_lemma u#b (); map_extensionality_lemma u#b (); disjoint_lemma u#b ()
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.empty_or_items_occupied_lemma
val empty_or_items_occupied_lemma: Prims.unit -> Lemma (empty_or_items_occupied_fact u#b)
val empty_or_items_occupied_lemma: Prims.unit -> Lemma (empty_or_items_occupied_fact u#b)
let empty_or_items_occupied_lemma () : Lemma (empty_or_items_occupied_fact u#b) = introduce forall (a: eqtype) (b: Type u#b) (m: map a b). m == emptymap \/ (exists item. (items m) item) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists item. (items m) item) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((items m) (k, v)) )
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 217, "start_col": 0, "start_line": 201 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) ) let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () ) let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists v. (values m) v) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.empty_or_items_occupied_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteMap.Base.map", "Prims.l_or", "Prims.eq2", "FStar.FiniteMap.Base.emptymap", "Prims.l_Exists", "FStar.Pervasives.Native.tuple2", "FStar.FiniteMap.Base.items", "Prims.op_Equality", "Prims.int", "FStar.FiniteSet.Base.cardinality", "FStar.FiniteMap.Base.domain", "FStar.Classical.Sugar.or_intro_left", "Prims.squash", "Prims.l_not", "FStar.FiniteMap.Base.values", "FStar.FiniteMap.Base.cardinality_zero_iff_empty_lemma", "Prims._assert", "Prims.b2t", "FStar.FiniteMap.Base.cardinality", "Prims.bool", "FStar.Classical.Sugar.or_intro_right", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.FiniteMap.Base.elements", "FStar.FiniteMap.Base.mem", "FStar.FiniteMap.Base.choose", "Prims.l_True", "FStar.FiniteMap.Base.empty_or_items_occupied_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let empty_or_items_occupied_lemma () : Lemma (empty_or_items_occupied_fact u#b) =
introduce forall (a: eqtype) (b: Type u#b) (m: map a b) . m == emptymap \/ (exists item. (items m) item) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left (assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b ()) else introduce m == emptymap \/ (exists item. (items m) item) with Right (let k = choose m in let v = Some?.v ((elements m) k) in assert ((items m) (k, v)))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.empty_or_values_occupied_lemma
val empty_or_values_occupied_lemma: Prims.unit -> Lemma (empty_or_values_occupied_fact u#b)
val empty_or_values_occupied_lemma: Prims.unit -> Lemma (empty_or_values_occupied_fact u#b)
let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists v. (values m) v) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v) )
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 199, "start_col": 0, "start_line": 183 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) ) let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.empty_or_values_occupied_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteMap.Base.map", "Prims.l_or", "Prims.eq2", "FStar.FiniteMap.Base.emptymap", "Prims.l_Exists", "FStar.FiniteMap.Base.values", "Prims.op_Equality", "Prims.int", "FStar.FiniteSet.Base.cardinality", "FStar.FiniteMap.Base.domain", "FStar.Classical.Sugar.or_intro_left", "Prims.squash", "Prims.l_not", "FStar.FiniteMap.Base.cardinality_zero_iff_empty_lemma", "Prims._assert", "Prims.b2t", "FStar.FiniteMap.Base.cardinality", "Prims.bool", "FStar.Classical.Sugar.or_intro_right", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.FiniteMap.Base.elements", "FStar.FiniteMap.Base.mem", "FStar.FiniteMap.Base.choose", "Prims.l_True", "FStar.FiniteMap.Base.empty_or_values_occupied_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) =
introduce forall (a: eqtype) (b: Type u#b) (m: map a b) . m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left (assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b ()) else introduce m == emptymap \/ (exists v. (values m) v) with Right (let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.cardinality_zero_iff_empty_lemma
val cardinality_zero_iff_empty_lemma: Prims.unit -> Lemma (cardinality_zero_iff_empty_fact u#b)
val cardinality_zero_iff_empty_lemma: Prims.unit -> Lemma (cardinality_zero_iff_empty_fact u#b)
let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) )
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 164, "start_col": 0, "start_line": 158 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.cardinality_zero_iff_empty_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteMap.Base.map", "Prims.l_iff", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.FiniteMap.Base.cardinality", "Prims.eq2", "FStar.FiniteMap.Base.emptymap", "FStar.Classical.Sugar.implies_intro", "Prims.squash", "Prims._assert", "FStar.FunctionalExtensionality.feq", "FStar.Pervasives.Native.option", "FStar.FiniteMap.Base.elements", "Prims.l_True", "FStar.FiniteMap.Base.cardinality_zero_iff_empty_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) =
introduce forall (a: eqtype) (b: Type u#b) (m: map a b) . cardinality m = 0 <==> m == emptymap with (introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)))
false
Vale.AES.Types_helpers.fsti
Vale.AES.Types_helpers.pow2_24
val pow2_24 : Prims.int
let pow2_24 = 0x1000000
{ "file_name": "vale/code/crypto/aes/Vale.AES.Types_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 12, "start_col": 7, "start_line": 12 }
module Vale.AES.Types_helpers open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Lib.Seqs
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.Types_helpers.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let pow2_24 =
0x1000000
false
Vale.AES.Types_helpers.fsti
Vale.AES.Types_helpers.nat24
val nat24 : Type0
let nat24 = natN pow2_24
{ "file_name": "vale/code/crypto/aes/Vale.AES.Types_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 13, "start_col": 0, "start_line": 13 }
module Vale.AES.Types_helpers open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Lib.Seqs
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.Types_helpers.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.natN", "Vale.AES.Types_helpers.pow2_24" ]
[]
false
false
false
true
true
let nat24 =
natN pow2_24
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_insert_at_head
val dll_insert_at_head (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_head (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_head (as_list h0 d) n))
val dll_insert_at_head (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_head (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_head (as_list h0 d) n))
let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 69, "end_line": 579, "start_col": 0, "start_line": 568 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll t -> n: DoublyLinkedListIface.node t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_unchanged_node_vals_maintains_changes", "DoublyLinkedListIface.as_list", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "DoublyLinkedListIface._lemma_unchanged_node_vals_transitive", "LowStar.BufferOps.op_Star_Equals", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.dll_insert_at_head", "LowStar.BufferOps.op_Bang_Star", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let dll_insert_at_head #t d n =
let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d)
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.singleton_list_seq
val singleton_list_seq (#a:Type) (x:a) : Lemma (seq_of_list [x] == create 1 x)
val singleton_list_seq (#a:Type) (x:a) : Lemma (seq_of_list [x] == create 1 x)
let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x))
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 10, "start_col": 0, "start_line": 8 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.seq_of_list [x] == FStar.Seq.Base.create 1 x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.seq_of_list", "Prims.Cons", "Prims.Nil", "FStar.Seq.Base.create", "Prims.unit", "FStar.Seq.Properties.lemma_seq_of_list_index" ]
[]
true
false
true
false
false
let singleton_list_seq #a x =
lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x))
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.lemma_from_list_be
val lemma_from_list_be (l:list bool) : Lemma (ensures ( let s = seq_of_list l in from_list_be l == from_vec #(List.length l) s ))
val lemma_from_list_be (l:list bool) : Lemma (ensures ( let s = seq_of_list l in from_list_be l == from_vec #(List.length l) s ))
let lemma_from_list_be l = List.rev_involutive l; lemma_from_list_le (List.rev l)
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 66, "start_col": 0, "start_line": 64 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = () let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x)) #reset-options let rec list_append_length #a x y = match x with | [] -> () | _::t -> list_append_length t y let rec list_append_index #a x y i = match x with | [] -> () | h::t -> (if i > 0 then list_append_index t y (i - 1)) let append_list_seq #a x y = list_append_length x y; let n = List.length (x @ y) in let index_of_x_y (i:nat{i < n}) : a = index (seq_of_list (x @ y)) i in let index_of_append_x_y (i:nat{i < n}) : a = index (append (seq_of_list x) (seq_of_list y)) i in let f (i:nat{i < n}) : Lemma (index_of_x_y i == index_of_append_x_y i) = list_append_index x y i; lemma_seq_of_list_index (x @ y) i; ( if i < List.length x then lemma_seq_of_list_index x i else lemma_seq_of_list_index y (i - List.length x) ) in FStar.Classical.forall_intro f; assert (equal (seq_of_list (x @ y)) (append (seq_of_list x) (seq_of_list y))) #reset-options "--z3rlimit 20" let rec lemma_from_list_le l = match l with | [] -> () | h::t -> ( lemma_from_list_le t; let rl = List.rev l in let rt = List.rev t in let sl = seq_of_list rl in let st = seq_of_list rt in let sh = create 1 h in let n = length st in rev_length l; rev_length t; rev_append [h] t; singleton_list_rev h; list_cons_is_append h t; append_list_seq rt [h]; singleton_list_seq h; assert (equal st (slice sl 0 n)) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Prims.bool -> FStar.Pervasives.Lemma (ensures (let s = FStar.Seq.Base.seq_of_list l in Vale.Lib.Lists.from_list_be l == FStar.UInt.from_vec s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.bool", "Vale.Lib.Lists.lemma_from_list_le", "FStar.List.Tot.Base.rev", "Prims.unit", "FStar.List.Tot.Properties.rev_involutive" ]
[]
true
false
true
false
false
let lemma_from_list_be l =
List.rev_involutive l; lemma_from_list_le (List.rev l)
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.list_append_length
val list_append_length (#a:Type) (x y:list a) : Lemma (List.length (x @ y) == List.length x + List.length y)
val list_append_length (#a:Type) (x y:list a) : Lemma (List.length (x @ y) == List.length x + List.length y)
let rec list_append_length #a x y = match x with | [] -> () | _::t -> list_append_length t y
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 16, "start_col": 0, "start_line": 13 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = () let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x)) #reset-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.list a -> y: Prims.list a -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.length (x @ y) == FStar.List.Tot.Base.length x + FStar.List.Tot.Base.length y)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Vale.Lib.Lists.list_append_length", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec list_append_length #a x y =
match x with | [] -> () | _ :: t -> list_append_length t y
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.append_list_seq
val append_list_seq (#a:Type) (x y:list a) : Lemma (seq_of_list (x @ y) == append (seq_of_list x) (seq_of_list y))
val append_list_seq (#a:Type) (x y:list a) : Lemma (seq_of_list (x @ y) == append (seq_of_list x) (seq_of_list y))
let append_list_seq #a x y = list_append_length x y; let n = List.length (x @ y) in let index_of_x_y (i:nat{i < n}) : a = index (seq_of_list (x @ y)) i in let index_of_append_x_y (i:nat{i < n}) : a = index (append (seq_of_list x) (seq_of_list y)) i in let f (i:nat{i < n}) : Lemma (index_of_x_y i == index_of_append_x_y i) = list_append_index x y i; lemma_seq_of_list_index (x @ y) i; ( if i < List.length x then lemma_seq_of_list_index x i else lemma_seq_of_list_index y (i - List.length x) ) in FStar.Classical.forall_intro f; assert (equal (seq_of_list (x @ y)) (append (seq_of_list x) (seq_of_list y)))
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 39, "start_col": 0, "start_line": 23 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = () let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x)) #reset-options let rec list_append_length #a x y = match x with | [] -> () | _::t -> list_append_length t y let rec list_append_index #a x y i = match x with | [] -> () | h::t -> (if i > 0 then list_append_index t y (i - 1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.list a -> y: Prims.list a -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.seq_of_list (x @ y) == FStar.Seq.Base.append (FStar.Seq.Base.seq_of_list x) (FStar.Seq.Base.seq_of_list y))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.seq_of_list", "FStar.List.Tot.Base.op_At", "FStar.Seq.Base.append", "Prims.unit", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.List.Tot.Base.length", "FStar.Seq.Properties.lemma_seq_of_list_index", "Prims.bool", "Prims.op_Subtraction", "Vale.Lib.Lists.list_append_index", "FStar.Seq.Base.index", "Vale.Lib.Lists.list_append_length" ]
[]
false
false
true
false
false
let append_list_seq #a x y =
list_append_length x y; let n = List.length (x @ y) in let index_of_x_y (i: nat{i < n}) : a = index (seq_of_list (x @ y)) i in let index_of_append_x_y (i: nat{i < n}) : a = index (append (seq_of_list x) (seq_of_list y)) i in let f (i: nat{i < n}) : Lemma (index_of_x_y i == index_of_append_x_y i) = list_append_index x y i; lemma_seq_of_list_index (x @ y) i; (if i < List.length x then lemma_seq_of_list_index x i else lemma_seq_of_list_index y (i - List.length x)) in FStar.Classical.forall_intro f; assert (equal (seq_of_list (x @ y)) (append (seq_of_list x) (seq_of_list y)))
false
Steel.ST.HigherArray.fst
Steel.ST.HigherArray.share
val share (#opened: _) (#elt: Type) (#x: Seq.seq elt) (a: array elt) (p p1 p2: P.perm) : STGhost unit opened (pts_to a p x) (fun _ -> pts_to a p1 x `star` pts_to a p2 x) (p == p1 `P.sum_perm` p2) (fun _ -> True)
val share (#opened: _) (#elt: Type) (#x: Seq.seq elt) (a: array elt) (p p1 p2: P.perm) : STGhost unit opened (pts_to a p x) (fun _ -> pts_to a p1 x `star` pts_to a p2 x) (p == p1 `P.sum_perm` p2) (fun _ -> True)
let share #_ #_ #x a p p1 p2 = elim_pts_to a p x; mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2; R.split (ptr_of a).base _ (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2); intro_pts_to a p1 x; intro_pts_to a p2 x
{ "file_name": "lib/steel/Steel.ST.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 349, "start_col": 0, "start_line": 341 }
(* Copyright 2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.HigherArray module P = Steel.PCMFrac module R = Steel.ST.PCMReference module M = FStar.Map module PM = Steel.PCMMap [@@noextract_to "krml"] let index_t (len: Ghost.erased nat) : Tot Type0 = (i: nat { i < len }) [@@noextract_to "krml"] let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type = PM.map (index_t len) (P.fractional elt) [@@noextract_to "krml"] let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) = PM.pointwise (index_t len) (P.pcm_frac #elt) [@@noextract_to "krml"] let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable [@@noextract_to "krml"] let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op [@@noextract_to "krml"] let mk_carrier (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: P.perm) : Tot (carrier elt len) = let f (i: nat) : Tot (P.fractional elt) = if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s then None else Some (Seq.index s (i - offset), p) in M.map_literal f let mk_carrier_inj (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\ offset + Seq.length s2 <= len )) (ensures ( s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2) )) = assert (forall (i: nat) . i < Seq.length s1 ==> (M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1))); assert (forall (i: nat) . i < Seq.length s2 ==> M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b) [@@noextract_to "krml"] noeq type ptr (elt: Type u#a) : Type0 = { base_len: Ghost.erased US.t; // U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 }); offset: (offset: nat { offset <= US.v base_len }); } let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 } let is_null_ptr p = is_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr _ = () let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: P.perm) : Tot prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one)) [@__reduce__] let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop = R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star` pure ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop = pts_to0 a p s // this lemma is necessary because Steel.PCMReference is marked unfold let change_r_pts_to (#opened: _) (#carrier: Type u#1) (#pcm: P.pcm carrier) (p: ref carrier pcm) (v: carrier) (#carrier': Type u#1) (#pcm': P.pcm carrier') (p': ref carrier' pcm') (v': carrier') : STGhost unit opened (R.pts_to p v) (fun _ -> R.pts_to p' v') (// keep on distinct lines for error messages carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v') (fun _ -> True) = rewrite (R.pts_to p v) (R.pts_to p' v') let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) ( v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) (fun _ -> True) = change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p); intro_pure _; rewrite (pts_to0 a p s) (pts_to a p s) let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p)) (True) (fun _ -> valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) = rewrite (pts_to a p s) (pts_to0 a p s); elim_pure _ let pts_to_length a s = elim_pts_to a _ s; intro_pts_to a _ s let pts_to_not_null a s = elim_pts_to a _ s; R.pts_to_not_null _ _; intro_pts_to a _ s let mk_carrier_joinable (#elt: Type) (len: nat) (offset: nat) (s1: Seq.seq elt) (p1: P.perm) (s2: Seq.seq elt) (p2: P.perm) : Lemma (requires ( offset + Seq.length s1 <= len /\ Seq.length s1 == Seq.length s2 /\ P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2) )) (ensures ( s1 `Seq.equal` s2 )) = let lem (i: nat { 0 <= i /\ i < Seq.length s1 }) : Lemma (Seq.index s1 i == Seq.index s2 i) [SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)] = assert ( forall z . ( P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\ P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z ) ==> begin match M.sel z (offset + i) with | None -> False | Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i end ) in () let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem) : Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==> interp p m /\ q) = pure_star_interp p q m; emp_unit p let pts_to_inj a p1 s1 p2 s2 m = Classical.forall_intro reveal_pure; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\ Seq.length s1 == length a ) m; pure_star_interp' (hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2))) ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\ Seq.length s2 == length a ) m; pts_to_join (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2) m; mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2 [@@noextract_to "krml"] let malloc0 (#elt: Type) (x: elt) (n: US.t) : ST (array elt) emp (fun a -> pts_to a P.full_perm (Seq.create (US.v n) x)) (True) (fun a -> length a == US.v n /\ base_len (base (ptr_of a)) == US.v n ) = let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in R.pts_to_not_null base _; let p = { base_len = n; base = base; offset = 0; } in let a = (| p, Ghost.hide (US.v n) |) in change_r_pts_to base c (ptr_of a).base c; intro_pts_to a P.full_perm (Seq.create (US.v n) x); return a let malloc_ptr x n = let a = malloc0 x n in let (| p, _ |) = a in rewrite (pts_to _ _ _) (pts_to (| p, Ghost.hide (US.v n) |) _ _); return p [@@noextract_to "krml"] let free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt) : ST unit (pts_to a P.full_perm s) (fun _ -> emp) ( length a == base_len (base (ptr_of a)) ) (fun _ -> True) = drop (pts_to a _ _) let free_ptr a = free0 _ let valid_sum_perm (len: nat) (offset: nat) (slice_len: nat) (p1 p2: P.perm) : Tot prop = let open FStar.Real in valid_perm len offset slice_len (P.sum_perm p1 p2) let mk_carrier_share (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires (valid_sum_perm len offset (Seq.length s) p1 p2)) (ensures ( let c1 = mk_carrier len offset s p1 in let c2 = mk_carrier len offset s p2 in composable c1 c2 /\ mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2) )) = ()
{ "checked_file": "/", "dependencies": [ "Steel.ST.PCMReference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.PCMMap.fst.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Steel.PCMMap", "short_module": "PM" }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "M" }, { "abbrev": true, "full_module": "Steel.ST.PCMReference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.PCMFrac", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.HigherArray.array elt -> p: Steel.FractionalPermission.perm -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "FStar.Seq.Base.seq", "Steel.ST.HigherArray.array", "Steel.FractionalPermission.perm", "Steel.ST.HigherArray.intro_pts_to", "Steel.ST.HigherArray.mk_carrier", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.SizeT.t", "Steel.ST.HigherArray.__proj__Mkptr__item__base_len", "Steel.ST.HigherArray.ptr_of", "Steel.ST.HigherArray.__proj__Mkptr__item__offset", "Prims.unit", "Steel.ST.PCMReference.split", "Steel.ST.HigherArray.carrier", "FStar.Ghost.hide", "Prims.nat", "Steel.ST.HigherArray.pcm", "Steel.ST.HigherArray.__proj__Mkptr__item__base", "Steel.ST.HigherArray.mk_carrier_share", "Steel.ST.HigherArray.elim_pts_to" ]
[]
false
true
false
false
false
let share #_ #_ #x a p p1 p2 =
elim_pts_to a p x; mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2; R.split (ptr_of a).base _ (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1) (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2); intro_pts_to a p1 x; intro_pts_to a p2 x
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.list_append_index
val list_append_index (#a:Type) (x y:list a) (i:nat) : Lemma (requires i < List.length (x @ y)) (ensures ( let nx = List.length x in (i >= nx ==> i - nx < List.length y) /\ List.index (x @ y) i == (if i < nx then List.index x i else List.index y (i - nx)) ))
val list_append_index (#a:Type) (x y:list a) (i:nat) : Lemma (requires i < List.length (x @ y)) (ensures ( let nx = List.length x in (i >= nx ==> i - nx < List.length y) /\ List.index (x @ y) i == (if i < nx then List.index x i else List.index y (i - nx)) ))
let rec list_append_index #a x y i = match x with | [] -> () | h::t -> (if i > 0 then list_append_index t y (i - 1))
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 21, "start_col": 0, "start_line": 18 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = () let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x)) #reset-options let rec list_append_length #a x y = match x with | [] -> () | _::t -> list_append_length t y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.list a -> y: Prims.list a -> i: Prims.nat -> FStar.Pervasives.Lemma (requires i < FStar.List.Tot.Base.length (x @ y)) (ensures (let nx = FStar.List.Tot.Base.length x in (i >= nx ==> i - nx < FStar.List.Tot.Base.length y) /\ FStar.List.Tot.Base.index (x @ y) i == ((match i < nx with | true -> FStar.List.Tot.Base.index x i | _ -> FStar.List.Tot.Base.index y (i - nx)) <: a)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.op_GreaterThan", "Vale.Lib.Lists.list_append_index", "Prims.op_Subtraction", "Prims.bool", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec list_append_index #a x y i =
match x with | [] -> () | h :: t -> (if i > 0 then list_append_index t y (i - 1))
false
Vale.AES.Types_helpers.fsti
Vale.AES.Types_helpers.lemma_ishl_64
val lemma_ishl_64 (x: nat64) (k: nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64)
val lemma_ishl_64 (x: nat64) (k: nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64)
let lemma_ishl_64 (x:nat64) (k:nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64) = Vale.Def.TypesNative_s.reveal_ishl 64 x k; FStar.UInt.shift_left_value_lemma #64 x k; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.Types_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 40, "start_col": 0, "start_line": 35 }
module Vale.AES.Types_helpers open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Lib.Seqs unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 val lemma_slices_le_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = le_quad32_to_bytes q in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) val lemma_slices_be_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = be_quad32_to_bytes q in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) val lemma_BitwiseXorWithZero64 (n:nat64) : Lemma (ixor n 0 == n)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.Types_helpers.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat64 -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ishl x k == x * Prims.pow2 k % Vale.Def.Words_s.pow2_64)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.UInt.shift_left_value_lemma", "Vale.Def.TypesNative_s.reveal_ishl", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_64", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_ishl_64 (x: nat64) (k: nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64) =
Vale.Def.TypesNative_s.reveal_ishl 64 x k; FStar.UInt.shift_left_value_lemma #64 x k; ()
false
Vale.Lib.Lists.fst
Vale.Lib.Lists.lemma_from_list_le
val lemma_from_list_le (l:list bool) : Lemma (ensures ( let rl = List.rev l in let s = seq_of_list rl in from_list_le l == from_vec #(List.length rl) s ))
val lemma_from_list_le (l:list bool) : Lemma (ensures ( let rl = List.rev l in let s = seq_of_list rl in from_list_le l == from_vec #(List.length rl) s ))
let rec lemma_from_list_le l = match l with | [] -> () | h::t -> ( lemma_from_list_le t; let rl = List.rev l in let rt = List.rev t in let sl = seq_of_list rl in let st = seq_of_list rt in let sh = create 1 h in let n = length st in rev_length l; rev_length t; rev_append [h] t; singleton_list_rev h; list_cons_is_append h t; append_list_seq rt [h]; singleton_list_seq h; assert (equal st (slice sl 0 n)) )
{ "file_name": "vale/code/lib/collections/Vale.Lib.Lists.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 62, "start_col": 0, "start_line": 42 }
module Vale.Lib.Lists open FStar.Mul #reset-options "--initial_fuel 2 --max_fuel 2" let singleton_list_rev #a x = () let list_cons_is_append #a h t = () let singleton_list_seq #a x = lemma_seq_of_list_index [x] 0; assert (equal (seq_of_list [x]) (create 1 x)) #reset-options let rec list_append_length #a x y = match x with | [] -> () | _::t -> list_append_length t y let rec list_append_index #a x y i = match x with | [] -> () | h::t -> (if i > 0 then list_append_index t y (i - 1)) let append_list_seq #a x y = list_append_length x y; let n = List.length (x @ y) in let index_of_x_y (i:nat{i < n}) : a = index (seq_of_list (x @ y)) i in let index_of_append_x_y (i:nat{i < n}) : a = index (append (seq_of_list x) (seq_of_list y)) i in let f (i:nat{i < n}) : Lemma (index_of_x_y i == index_of_append_x_y i) = list_append_index x y i; lemma_seq_of_list_index (x @ y) i; ( if i < List.length x then lemma_seq_of_list_index x i else lemma_seq_of_list_index y (i - List.length x) ) in FStar.Classical.forall_intro f; assert (equal (seq_of_list (x @ y)) (append (seq_of_list x) (seq_of_list y)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.Lists.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Prims.bool -> FStar.Pervasives.Lemma (ensures (let rl = FStar.List.Tot.Base.rev l in let s = FStar.Seq.Base.seq_of_list rl in Vale.Lib.Lists.from_list_le l == FStar.UInt.from_vec s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.bool", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.unit", "Vale.Lib.Lists.singleton_list_seq", "Vale.Lib.Lists.append_list_seq", "Prims.Cons", "Prims.Nil", "Vale.Lib.Lists.list_cons_is_append", "Vale.Lib.Lists.singleton_list_rev", "FStar.List.Tot.Properties.rev_append", "FStar.List.Tot.Properties.rev_length", "Prims.nat", "FStar.Seq.Base.length", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Prims.eq2", "FStar.List.Tot.Base.length", "FStar.Seq.Base.seq_of_list", "FStar.List.Tot.Base.rev", "Vale.Lib.Lists.lemma_from_list_le" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_from_list_le l =
match l with | [] -> () | h :: t -> (lemma_from_list_le t; let rl = List.rev l in let rt = List.rev t in let sl = seq_of_list rl in let st = seq_of_list rt in let sh = create 1 h in let n = length st in rev_length l; rev_length t; rev_append [h] t; singleton_list_rev h; list_cons_is_append h t; append_list_seq rt [h]; singleton_list_seq h; assert (equal st (slice sl 0 n)))
false
FStar.FiniteMap.Base.fst
FStar.FiniteMap.Base.map_extensionality_lemma
val map_extensionality_lemma: Prims.unit -> Lemma (map_extensionality_fact u#b)
val map_extensionality_lemma: Prims.unit -> Lemma (map_extensionality_fact u#b)
let map_extensionality_lemma () : Lemma (map_extensionality_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m1: map a b) (m2: map a b). equal m1 m2 ==> m1 == m2 with ( introduce equal m1 m2 ==> m1 == m2 with _. ( assert (FSet.equal (domain m1) (domain m2)); assert (feq (elements m1) (elements m2)) ) )
{ "file_name": "ulib/FStar.FiniteMap.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 294, "start_col": 0, "start_line": 285 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base open FStar.FiniteSet.Ambient module T = FStar.Tactics.V2 // Finite maps type map (a: eqtype) (b: Type u#b) = (keys: FSet.set a) & (setfun_t a b keys) let domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a = let (| keys, _ |) = m in keys let elements (#a: eqtype) (#b: Type u#b) (m: map a b) : (setfun_t a b (domain m)) = let (| _, f |) = m in f let rec key_list_to_item_list (#a: eqtype) (#b: Type u#b) (m: map a b) (keys: list a{FSet.list_nonrepeating keys /\ (forall key. FLT.mem key keys ==> FSet.mem key (domain m))}) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. FLT.mem key keys <==> key_in_item_list key items)}) (decreases keys) = match keys with | [] -> [] | key :: remaining_keys -> (key, Some?.v ((elements m) key)) :: key_list_to_item_list m remaining_keys let map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) = key_list_to_item_list m (FSet.set_as_list (domain m)) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; let cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat = FSet.cardinality (domain m) /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; let values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) = fun value -> exists key. ((elements m) key == Some value) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; let items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) = fun item -> ((elements m) (fst item) == Some (snd item)) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; let emptymap (#a: eqtype) (#b: Type u#b) : (map a b) = (| FSet.emptyset, on_domain a (fun key -> None) |) /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; let glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b = (| keys, f |) /// We represent the Dafny function `Map#Build` with `build`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; let insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b = let keys' = FSet.insert k (domain m) in let f' = on_domain a (fun key -> if key = k then Some v else (elements m) key) in (| keys', f' |) /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; let merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b = let keys' = FSet.union (domain m1) (domain m2) in let f' = on_domain a (fun key -> if FSet.mem key (domain m2) then (elements m2) key else (elements m1) key) in (| keys', f' |) /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; let subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b = let keys' = FSet.difference (domain m) s in let f' = on_domain a (fun key -> if FSet.mem key keys' then (elements m) key else None) in (| keys', f' |) /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; let equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = feq (elements m1) (elements m2) /\ True //a bit ugly, a prop coercion /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; let disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop = FSet.disjoint (domain m1) (domain m2) /\ True //prop coercion /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) = FSet.choose (domain m) /// We now prove each of the facts that comprise `all_finite_map_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. let cardinality_zero_iff_empty_lemma () : Lemma (cardinality_zero_iff_empty_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). cardinality m = 0 <==> m == emptymap with ( introduce cardinality m = 0 ==> m == emptymap with _. assert (feq (elements m) (elements emptymap)) ) let empty_or_domain_occupied_lemma () : Lemma (empty_or_domain_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists k. mem k m) with ( if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists k. mem k m) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma () ) else introduce m == emptymap \/ (exists k. mem k m) with Right () ) let empty_or_values_occupied_lemma () : Lemma (empty_or_values_occupied_fact u#b) = introduce forall (a: eqtype) (b:Type u#b) (m: map a b). m == emptymap \/ (exists v. (values m) v) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists v. (values m) v) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((values m) v) ) let empty_or_items_occupied_lemma () : Lemma (empty_or_items_occupied_fact u#b) = introduce forall (a: eqtype) (b: Type u#b) (m: map a b). m == emptymap \/ (exists item. (items m) item) with if FSet.cardinality (domain m) = 0 then introduce m == emptymap \/ (exists v. (values m) v) with Left ( assert (cardinality m = 0); cardinality_zero_iff_empty_lemma u#b () ) else introduce m == emptymap \/ (exists item. (items m) item) with Right ( let k = choose m in let v = Some?.v ((elements m) k) in assert ((items m) (k, v)) ) let map_cardinality_matches_domain_lemma () : Lemma (map_cardinality_matches_domain_fact u#b) = () let values_contains_lemma () : Lemma (values_contains_fact u#b) = () let items_contains_lemma () : Lemma (items_contains_fact u#b) = () let empty_domain_empty_lemma () : Lemma (empty_domain_empty_fact u#b) = () let glue_domain_lemma () : Lemma (glue_domain_fact u#b) = () let glue_elements_lemma () : Lemma (glue_elements_fact u#b) = () let insert_elements_lemma () : Lemma (insert_elements_fact u#b) = () let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact u#b) = () let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact u#b) = () let merge_domain_is_union_lemma () : Lemma (merge_domain_is_union_fact u#b) = () let merge_element_lemma () : Lemma (merge_element_fact u#b) = () let subtract_domain_lemma () : Lemma (subtract_domain_fact u#b) = () let subtract_element_lemma () : Lemma (subtract_element_fact u#b) = () let map_equal_lemma () : Lemma (map_equal_fact u#b) //Surprising; needed to split this goal into two = assert (map_equal_fact u#b) by (T.norm [delta_only [`%map_equal_fact]]; let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in let _ = T.forall_intro () in T.split (); T.smt(); T.smt())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked", "FStar.FiniteSet.Ambient.fst.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteMap.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.FiniteSet.Ambient", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteMap.Base.map_extensionality_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteMap.Base.map", "Prims.l_imp", "FStar.FiniteMap.Base.equal", "Prims.eq2", "FStar.Classical.Sugar.implies_intro", "Prims.squash", "Prims._assert", "FStar.FunctionalExtensionality.feq", "FStar.Pervasives.Native.option", "FStar.FiniteMap.Base.elements", "FStar.FiniteSet.Base.equal", "FStar.FiniteMap.Base.domain", "Prims.l_True", "FStar.FiniteMap.Base.map_extensionality_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let map_extensionality_lemma () : Lemma (map_extensionality_fact u#b) =
introduce forall (a: eqtype) (b: Type u#b) (m1: map a b) (m2: map a b) . equal m1 m2 ==> m1 == m2 with (introduce equal m1 m2 ==> m1 == m2 with _. (assert (FSet.equal (domain m1) (domain m2)); assert (feq (elements m1) (elements m2))))
false
Vale.AES.Types_helpers.fsti
Vale.AES.Types_helpers.lemma_ishr_32
val lemma_ishr_32 (x: nat32) (k: nat) : Lemma (ensures ishr #pow2_32 x k == x / pow2 k)
val lemma_ishr_32 (x: nat32) (k: nat) : Lemma (ensures ishr #pow2_32 x k == x / pow2 k)
let lemma_ishr_32 (x:nat32) (k:nat) : Lemma (ensures ishr #pow2_32 x k == x / pow2 k) = Vale.Def.TypesNative_s.reveal_ishr 32 x k; FStar.UInt.shift_right_value_lemma #32 x k; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.Types_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 54, "start_col": 0, "start_line": 49 }
module Vale.AES.Types_helpers open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Lib.Seqs unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 val lemma_slices_le_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = le_quad32_to_bytes q in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) val lemma_slices_be_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = be_quad32_to_bytes q in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) val lemma_BitwiseXorWithZero64 (n:nat64) : Lemma (ixor n 0 == n) let lemma_ishl_64 (x:nat64) (k:nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64) = Vale.Def.TypesNative_s.reveal_ishl 64 x k; FStar.UInt.shift_left_value_lemma #64 x k; () let lemma_ishr_64 (x:nat64) (k:nat) : Lemma (ensures ishr #pow2_64 x k == x / pow2 k) = Vale.Def.TypesNative_s.reveal_ishr 64 x k; FStar.UInt.shift_right_value_lemma #64 x k; ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.Types_helpers.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ishr x k == x / Prims.pow2 k)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Prims.nat", "Prims.unit", "FStar.UInt.shift_right_value_lemma", "Vale.Def.TypesNative_s.reveal_ishr", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Vale.Def.Types_s.ishr", "Vale.Def.Words_s.pow2_32", "Prims.op_Division", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_ishr_32 (x: nat32) (k: nat) : Lemma (ensures ishr #pow2_32 x k == x / pow2 k) =
Vale.Def.TypesNative_s.reveal_ishr 32 x k; FStar.UInt.shift_right_value_lemma #32 x k; ()
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_insert_at_tail
val dll_insert_at_tail (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_tail (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_tail (as_list h0 d) n))
val dll_insert_at_tail (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_tail (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_tail (as_list h0 d) n))
let dll_insert_at_tail #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); // OBSERVE _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n]
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 62, "end_line": 603, "start_col": 0, "start_line": 585 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list let as_list h d = (d@h).DLL.nodes /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList let dll_new () = B.alloca DLL.empty_list 1ul let is_empty d = B.is_null (!*d).DLL.lhead let dll_head d = (!*d).DLL.lhead let dll_tail d = let h0 = HST.get () in L.lemma_unsnoc_is_last (as_list h0 d); (!*d).DLL.ltail /// Useful auxiliary lemmas (** If a node is inside a valid list, then the node is valid. *) val lemma_node_in_valid_dll_is_valid (h:HS.mem) (d:dll 'a) (n:node 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (node_valid h n)) let lemma_node_in_valid_dll_is_valid h d n = let pos = L.index_of (as_list h d) n in DLL.extract_nodelist_contained h (as_list h d) pos (** Aux lemma *) val _lemma_nodelist_contained_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ (DLL.nodelist_contained0 h0 nl))) (ensures (DLL.nodelist_contained0 h1 nl)) let rec _lemma_nodelist_contained_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_contained_in_unmodified_mem h0 h1 s ns (** Aux lemma *) val _lemma_nodelist_conn_in_unmodified_mem (h0 h1:HS.mem) (s:B.loc) (nl:list (node 'a)) : Lemma (requires (B.modifies s h0 h1 /\ B.loc_disjoint s (DLL.nodelist_fp0 nl) /\ DLL.nodelist_contained0 h0 nl /\ (DLL.nodelist_conn h0 nl))) (ensures (DLL.nodelist_conn h1 nl)) let rec _lemma_nodelist_conn_in_unmodified_mem h0 h1 s nl = match nl with | [] -> () | n1 :: rest -> match rest with | [] -> () | n2 :: ns -> _lemma_nodelist_conn_in_unmodified_mem h0 h1 s rest (** Aux lemma *) val _lemma_nodelist_disjoint_in_push (h0 h1:HS.mem) (nl:list (node 'a)) : Lemma (requires (HS.fresh_frame h0 h1 /\ DLL.nodelist_contained0 h0 nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_disjoint` (B.loc_region_only false (HS.get_tip h1)))) let rec _lemma_nodelist_disjoint_in_push h0 h1 nl = match nl with | [] -> () | n :: ns -> _lemma_nodelist_disjoint_in_push h0 h1 ns (** If a new frame is pushed, then a dll remains valid and unchanged. *) val _auto_dll_valid_and_unchanged_through_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_valid_and_unchanged_through_push h0 h1 d = B.fresh_frame_modifies h0 h1; _lemma_nodelist_contained_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 B.loc_none (as_list h1 d) (** If a frame is popped, then a dll remains valid and unchanged. *) val _lemma_dll_valid_and_unchanged_through_pop (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.popped h0 h1 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h0)))) (ensures (dll_valid h1 d /\ d@h0 == d@h1)) let _lemma_dll_valid_and_unchanged_through_pop h0 h1 d = B.popped_modifies h0 h1; assert (B.loc_region_only false (HS.get_tip h0) `B.loc_includes` B.loc_region_only false (HS.get_tip h0)); // OBSERVE let loc = B.loc_region_only false (HS.get_tip h0) in _lemma_nodelist_contained_in_unmodified_mem h0 h1 loc (as_list h1 d); _lemma_nodelist_conn_in_unmodified_mem h0 h1 loc (as_list h1 d) (** If stack discipline is followed, then a valid modification inside a push-pop pair is also valid outside of it. *) val _auto_dll_modified_with_push_pop (h0 h1:HS.mem) (d:dll 'a) (h2 h3:HS.mem) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1 /\ B.modifies (B.loc_union (fp_dll h0 d) (fp_dll h3 d)) h1 h2 /\ B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h2)) /\ B.loc_disjoint (fp_dll h3 d) (B.loc_region_only false (HS.get_tip h2)) /\ HS.get_tip h1 == HS.get_tip h2 /\ dll_valid h2 d /\ HS.popped h2 h3)) (ensures (dll_valid h3 d)) [SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3); SMTPat (dll_valid h3 d)] let _auto_dll_modified_with_push_pop h0 h1 d h2 h3 = let loc = B.loc_region_only false (HS.get_tip h2) in B.popped_modifies h2 h3; _lemma_nodelist_contained_in_unmodified_mem h2 h3 loc (as_list h3 d); _lemma_nodelist_conn_in_unmodified_mem h2 h3 loc (as_list h3 d) (** If a new frame is pushed, the the dll's fp is disjoint from what just got pushed. *) val _auto_dll_fp_disjoint_from_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (B.loc_disjoint (fp_dll h0 d) (B.loc_region_only false (HS.get_tip h1)))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_dll_fp_disjoint_from_push h0 h1 d = _lemma_nodelist_disjoint_in_push h0 h1 (d@h0).DLL.nodes (** If a valid dll is placed into a pointer, it stays valid *) val _auto_dll_assign_valid_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (dll_valid h1 d)) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (dll_valid h1 d)] let _auto_dll_assign_valid_stays_valid h0 h1 d d2 = _lemma_nodelist_conn_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes; _lemma_nodelist_contained_in_unmodified_mem h0 h1 (B.loc_buffer d) d2.DLL.nodes (** [unchanged_node_vals] is transitive *) let rec _lemma_unchanged_node_vals_transitive (h0 h1 h2:HS.mem) (ns:list (node 'a)) : Lemma (requires ( (unchanged_node_vals h0 h1 ns) /\ (unchanged_node_vals h1 h2 ns))) (ensures ( (unchanged_node_vals h0 h2 ns))) = match ns with | [] -> () | _ :: ns' -> _lemma_unchanged_node_vals_transitive h0 h1 h2 ns' (** Auxiliary predicate: node list is disjoint from region *) let rec _pred_nl_disjoint (h:HS.mem) (ns:list (node 'a)) = DLL.nodelist_fp0 ns `B.loc_disjoint` B.loc_region_only false (HS.get_tip h) (** If [unchanged_node_vals] is true, then it remains true through a push-pop. *) val _auto_unchanged_node_vals_through_push_pop (h0 h1:HS.mem) (ns:list (node 'a)) (h2 h3:HS.mem) : Lemma (requires (unchanged_node_vals h1 h2 ns /\ HS.fresh_frame h0 h1 /\ HS.popped h2 h3 /\ _pred_nl_disjoint h1 ns /\ HS.get_tip h1 == HS.get_tip h2)) (ensures ( unchanged_node_vals h0 h1 ns /\ // used only for proof. not necessary outside unchanged_node_vals h2 h3 ns /\ // used only for proof. not necessary outside unchanged_node_vals h0 h3 ns)) [SMTPat (unchanged_node_vals h0 h3 ns); SMTPat (HS.fresh_frame h0 h1); SMTPat (HS.popped h2 h3)] let rec _auto_unchanged_node_vals_through_push_pop h0 h1 ns h2 h3 = match ns with | [] -> () | n :: ns' -> _auto_unchanged_node_vals_through_push_pop h0 h1 ns' h2 h3; // assert (unchanged_node_vals h0 h1 ns); // assert (unchanged_node_vals h2 h3 ns); B.popped_modifies h2 h3 (** If a valid dll has a frame pushed, [_pred_nl_disjoint] stays true *) val _auto_pred_nl_disjoint_push (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (dll_valid h0 d /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 (as_list h1 d))) [SMTPat (dll_valid h0 d); SMTPat (HS.fresh_frame h0 h1)] let _auto_pred_nl_disjoint_push h0 h1 d = let loc = B.loc_region_only false (HS.get_tip h1) in let rec aux (ns:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 ns /\ HS.fresh_frame h0 h1)) (ensures (_pred_nl_disjoint h1 ns)) = match ns with | [] -> () | n :: ns' -> aux ns' in aux (as_list h0 d) (** The impl version of [unchanged_node_vals] is same as iface one *) let rec _auto_unchanged_node_vals_DLL (h0 h1:HS.mem) (ns:list (node 'a)) : Lemma (requires (DLL.unchanged_node_vals h0 h1 ns)) (ensures (unchanged_node_vals h0 h1 ns)) [SMTPat (unchanged_node_vals h0 h1 ns)] = match ns with | [] -> () | _ :: ns' -> _auto_unchanged_node_vals_DLL h0 h1 ns' (** If a valid dll is placed into a pointer, its nodes stay unchanged *) val _auto_unchanged_node_vals_stays_valid (h0 h1:HS.mem) (d:dll 'a) (d2:DLL.dll 'a) : Lemma (requires (DLL.dll_valid h0 d2 /\ B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 d2 /\ B.live h0 d /\ d@h1 == d2)) (ensures (unchanged_node_vals h0 h1 (as_list h1 d))) [SMTPat (DLL.dll_valid h0 d2); SMTPat (B.modifies (B.loc_buffer d) h0 h1); SMTPat (unchanged_node_vals h0 h1 (as_list h1 d))] let _auto_unchanged_node_vals_stays_valid h0 h1 d d2 = let rec aux nl : Lemma (requires ( B.modifies (B.loc_buffer d) h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` B.loc_buffer d)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> aux ns in aux (as_list h1 d) (** If a nodelist is disjoint from a modification, it stays unchanged *) let rec _lemma_unchanged_node_vals_when_disjoint (h0 h1:HS.mem) loc nl : Lemma (requires ( B.modifies loc h0 h1 /\ DLL.nodelist_fp0 nl `B.loc_disjoint` loc)) (ensures (unchanged_node_vals h0 h1 nl)) = match nl with | [] -> () | n :: ns -> _lemma_unchanged_node_vals_when_disjoint h0 h1 loc ns (** If a dll is assigned to, its original nodes stay unchanged *) val _lemma_unchanged_node_vals_stays_valid0 (h0 h1:HS.mem) (d:dll 'a) : Lemma (requires (B.modifies (B.loc_buffer d) h0 h1 /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h0) /\ B.live h0 d)) (ensures (unchanged_node_vals h0 h1 (as_list h0 d))) let _lemma_unchanged_node_vals_stays_valid0 h0 h1 d = _lemma_unchanged_node_vals_when_disjoint h0 h1 (B.loc_buffer d) (as_list h0 d) (** If a node belongs to a dll, then its fp is included *) let rec _lemma_node_in_list_is_included (n:node 'a) (nl:list (node 'a)) : Lemma (requires (n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` fp_node n)) = match nl with | [_] -> () | n' :: ns -> FStar.Classical.or_elim #_ #_ #(fun () -> DLL.nodelist_fp0 nl `B.loc_includes` fp_node n) (fun (_:unit{n == n'}) -> ()) (fun (_:unit{n =!= n'}) -> _lemma_node_in_list_is_included n ns) (** If a node_or_null is null or belongs to a dll, then its fp is included *) let _lemma_node_in_list_or_null_is_included (n:B.pointer_or_null (DLL.node 'a)) (nl:list (node 'a)) : Lemma (requires (n =!= B.null ==> n `L.memP` nl)) (ensures (DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n)) = FStar.Classical.arrow_to_impl #(n =!= B.null) #(DLL.nodelist_fp0 nl `B.loc_includes` B.loc_buffer n) (fun _ -> _lemma_node_in_list_is_included n nl) (** If a node is in the list, then the node before it is also in the list if it is not null *) let _lemma_prev_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.blink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.blink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; DLL.extract_nodelist_conn h l (L.index_of l n - 1)) (** If a node is in the list, then the node after it is also in the list if it is not null *) let _lemma_next_node_in_list (h:HS.mem) (n:node 'a) (d:dll 'a) : Lemma (requires (dll_valid h d /\ n `L.memP` as_list h d)) (ensures (let n' = (n@h).DLL.flink in n' =!= B.null ==> n' `L.memP` as_list h d)) = let n' = (n@h).DLL.flink in let l = as_list h d in FStar.Classical.arrow_to_impl #(n' =!= B.null) #(n' =!= B.null /\ n' `L.memP` l) (fun _ -> lemma_node_in_valid_dll_is_valid h d n; L.lemma_unsnoc_is_last l; DLL.extract_nodelist_conn h l (L.index_of l n)) (** Insertion operations maintain membership *) let rec _lemma_insertion_maintains_memP (l1 l2:list 'a) (x0 x1 x:'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (x `L.memP` l1 \/ x == x1))) (ensures (x `L.memP` l2)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.or_elim #_ #_ #(fun () -> x `L.memP` l2) (fun (_:unit{x0' == x0 \/ x0' == x}) -> ()) (fun (_:unit{x0' =!= x0 /\ x0' =!= x}) -> _lemma_insertion_maintains_memP l1' (L.tl l2) x0 x1 x) (** Insertion operations maintain [unchanged_node_vals] *) let rec _lemma_insertion_maintains_unchanged_node_vals (h0 h1:HS.mem) (l1 l2:list (node 'a)) (x0 x1:node 'a) : Lemma (requires ((x0 `L.memP` l1) /\ ((l2 == DLL._l_insert_before x0 l1 x1) \/ (l2 == DLL._l_insert_after x0 l1 x1)) /\ (unchanged_node_vals h0 h1 l2))) (ensures (unchanged_node_vals h0 h1 l1)) = match l1 with | [_] -> () | x0' :: l1' -> FStar.Classical.arrow_to_impl #(x0 =!= x0') #(unchanged_node_vals h0 h1 l1) (fun _ -> _lemma_insertion_maintains_unchanged_node_vals h0 h1 l1' (L.tl l2) x0 x1) (** Unchanged node vals means that the payloads maintain the changes that happened *) let rec _lemma_unchanged_node_vals_maintains_changes (h0 h1:HS.mem) (l:list (node 'a)) : Lemma (requires (DLL.nodelist_contained h0 l /\ unchanged_node_vals h0 h1 l)) (ensures (g_node_vals h1 l == g_node_vals h0 l)) = match l with | [] -> () | h :: t -> _lemma_unchanged_node_vals_maintains_changes h0 h1 t (** Containment holds before/after [append]ing *) let rec _lemma_append_contains (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (DLL.nodelist_contained h0 (l1 `L.append` l2)) <==> (DLL.nodelist_contained h0 l1 /\ DLL.nodelist_contained h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_contains h0 t l2 (** [g_node_vals] before/after [append]ing *) let rec _lemma_append_g_node_vals (h0:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (g_node_vals h0 (l1 `L.append` l2) == g_node_vals h0 l1 `L.append` g_node_vals h0 l2))) = match l1 with | [] -> () | h :: t -> _lemma_append_g_node_vals h0 t l2 (** [unchanged_node_val] before/after [append]ing *) let rec _lemma_unchanged_node_vals_append (h0 h1:HS.mem) (l1 l2:list (node 'a)) : Lemma (ensures ( (unchanged_node_vals h0 h1 (l1 `L.append` l2) <==> (unchanged_node_vals h0 h1 l1 /\ unchanged_node_vals h0 h1 l2)))) = match l1 with | [] -> () | h :: t -> _lemma_unchanged_node_vals_append h0 h1 t l2 (** Getting a specific node from an [unchanged_node_val] *) let rec _lemma_extract_unchanged_node_val (h0 h1:HS.mem) (n:node 'a) (l:list (node 'a)) : Lemma (requires (unchanged_node_vals h0 h1 l /\ n `L.memP` l)) (ensures (unchanged_node_val h0 h1 n)) = let h :: t = l in FStar.Classical.or_elim #_ #_ #(fun () -> unchanged_node_val h0 h1 n) (fun (_:unit{n == h}) -> ()) (fun (_:unit{n =!= h}) -> _lemma_extract_unchanged_node_val h0 h1 n t) (** Connect [split_using] and [splitAt] *) let rec _lemma_split_using_splitAt (l:list 'a) (x:'a) : Lemma (requires (x `L.memP` l)) (ensures (l `L.split_using` x == L.splitAt (l `L.index_of` x) l)) = match l with | [_] -> () | h :: t -> FStar.Classical.arrow_to_impl #(x `L.memP` t) #(l `L.split_using` x == L.splitAt (l `L.index_of` x) l) (fun _ -> _lemma_split_using_splitAt t x) (** Length of a [g_node_vals] is same as orig list *) let rec _lemma_length_g_node_vals (h0:HS.mem) (l:list (node 'a)) : Lemma (L.length (g_node_vals h0 l) = L.length l) = match l with | [] -> () | h :: t -> _lemma_length_g_node_vals h0 t /// Moving forwards or backwards in a list let has_next d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.flink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n < L.length (as_list h0 d) - 1) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_tail_can_point_right_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) (L.length (as_list h0 d) - 1)); y let has_prev d n = let h0 = HST.get () in DLL.lemma_dll_links_contained h0 (d@h0) (as_list h0 d `L.index_of` n); L.lemma_unsnoc_is_last (as_list h0 d); let y = not (B.is_null (!*n).DLL.blink) in FStar.Classical.or_elim #_ #_ #(fun () -> y <==> as_list h0 d `L.index_of` n > 0) (fun (_:unit{y}) -> ()) (fun (_:unit{not y}) -> DLL._lemma_only_head_can_point_left_to_null h0 n (as_list h0 d); DLL._lemma_all_nodes_are_unique h0 (as_list h0 d) (as_list h0 d `L.index_of` n) 0); y let next_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n); (!*n).DLL.flink let prev_node d n = let h0 = HST.get () in lemma_node_in_valid_dll_is_valid h0 d n; DLL.extract_nodelist_conn h0 (as_list h0 d) (L.index_of (as_list h0 d) n - 1); (!*n).DLL.blink /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. #set-options "--z3rlimit 20 --max_fuel 2 --max_ifuel 1" let dll_insert_at_head #t d n = let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_head (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d) #reset-options #set-options "--z3rlimit 40 --max_fuel 2 --max_ifuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "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.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: DoublyLinkedListIface.dll t -> n: DoublyLinkedListIface.node t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedListIface._lemma_unchanged_node_vals_append", "DoublyLinkedListIface.as_list", "Prims.Cons", "Prims.Nil", "Prims.unit", "DoublyLinkedListIface._lemma_append_g_node_vals", "DoublyLinkedListIface._lemma_extract_unchanged_node_val", "FStar.List.Tot.Properties.lemma_unsnoc_is_last", "DoublyLinkedListIface._lemma_unchanged_node_vals_maintains_changes", "DoublyLinkedListIface._lemma_append_contains", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "DoublyLinkedListIface._lemma_unchanged_node_vals_transitive", "Prims._assert", "DoublyLinkedListIface._pred_nl_disjoint", "LowStar.BufferOps.op_Star_Equals", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.dll_insert_at_tail", "LowStar.BufferOps.op_Bang_Star", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let dll_insert_at_tail #t d n =
let h00 = HST.get () in HST.push_frame (); let h0 = HST.get () in let y = DLL.dll_insert_at_tail (!*d) n in let h' = HST.get () in d *= y; let h1 = HST.get () in assert (_pred_nl_disjoint h0 (as_list h1 d)); _lemma_unchanged_node_vals_transitive h0 h' h1 (as_list h1 d); HST.pop_frame (); let h11 = HST.get () in _lemma_append_contains h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_maintains_changes h00 h11 (as_list h1 d); _lemma_append_g_node_vals h11 (as_list h0 d) [n]; L.lemma_unsnoc_is_last (as_list h1 d); _lemma_extract_unchanged_node_val h0 h1 n (as_list h1 d); _lemma_append_g_node_vals h00 (as_list h0 d) [n]; _lemma_unchanged_node_vals_append h00 h11 (as_list h0 d) [n]
false
Vale.AES.Types_helpers.fsti
Vale.AES.Types_helpers.lemma_ishr_64
val lemma_ishr_64 (x: nat64) (k: nat) : Lemma (ensures ishr #pow2_64 x k == x / pow2 k)
val lemma_ishr_64 (x: nat64) (k: nat) : Lemma (ensures ishr #pow2_64 x k == x / pow2 k)
let lemma_ishr_64 (x:nat64) (k:nat) : Lemma (ensures ishr #pow2_64 x k == x / pow2 k) = Vale.Def.TypesNative_s.reveal_ishr 64 x k; FStar.UInt.shift_right_value_lemma #64 x k; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.Types_helpers.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 47, "start_col": 0, "start_line": 42 }
module Vale.AES.Types_helpers open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Lib.Seqs unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 val lemma_slices_le_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = le_quad32_to_bytes q in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) val lemma_slices_be_quad32_to_bytes (q:quad32) : Lemma (ensures ( let s = be_quad32_to_bytes q in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) val lemma_BitwiseXorWithZero64 (n:nat64) : Lemma (ixor n 0 == n) let lemma_ishl_64 (x:nat64) (k:nat) : Lemma (ensures ishl #pow2_64 x k == x * pow2 k % pow2_64) = Vale.Def.TypesNative_s.reveal_ishl 64 x k; FStar.UInt.shift_left_value_lemma #64 x k; ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.Types_helpers.fsti" }
[ { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat64 -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ishr x k == x / Prims.pow2 k)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.UInt.shift_right_value_lemma", "Vale.Def.TypesNative_s.reveal_ishr", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Vale.Def.Types_s.ishr", "Vale.Def.Words_s.pow2_64", "Prims.op_Division", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_ishr_64 (x: nat64) (k: nat) : Lemma (ensures ishr #pow2_64 x k == x / pow2 k) =
Vale.Def.TypesNative_s.reveal_ishr 64 x k; FStar.UInt.shift_right_value_lemma #64 x k; ()
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.uint8_p
val uint8_p : Type0
let uint8_p = B.buffer UInt8.t
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 17, "start_col": 0, "start_line": 17 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t" ]
[]
false
false
false
true
true
let uint8_p =
B.buffer UInt8.t
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.t128_mod
val t128_mod : Vale.Interop.Base.td
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 38, "start_col": 0, "start_line": 38 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.default_bq" ]
[]
false
false
false
true
false
let t128_mod =
TD_Buffer TUInt8 TUInt128 default_bq
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.uint64
val uint64 : Prims.eqtype
let uint64 = UInt64.t
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 27, "start_col": 0, "start_line": 27 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t" ]
[]
false
false
false
true
false
let uint64 =
UInt64.t
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.t128_no_mod
val t128_no_mod : Vale.Interop.Base.td
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 106, "end_line": 40, "start_col": 0, "start_line": 40 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Interop.Base.td
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.Mkbuffer_qualifiers", "Vale.Arch.HeapTypes_s.Secret" ]
[]
false
false
false
true
false
let t128_no_mod =
TD_Buffer TUInt8 TUInt128 ({ modified = false; strict_disjointness = false; taint = MS.Secret })
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key128_pre
val key128_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom
val key128_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom
let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 57, "start_col": 0, "start_line": 50 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) -> Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.AesHash.dom
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.AES.X64.GF128_Init.va_req_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_128", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.prop" ]
[]
false
false
false
true
false
let key128_pre: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom =
fun (s: Ghost.erased (Seq.seq nat32)) (c: V.va_code) (input_b: b128) (output_b: b128) (va_s0: V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.key_length
val key_length : a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Prims.int
let key_length (a: algorithm { a = AES_128 \/ a = AES_256 }) = match a with | AES_128 -> 16 | AES_256 -> 32
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 41, "start_col": 0, "start_line": 38 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s unfold let uint8_p = B.buffer UInt8.t let length_aux (b:uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db let length_aux2 (b:uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db inline_for_extraction unfold let key_offset (a: algorithm { a = AES_128 \/ a = AES_256 }) = match a with | AES_128 -> 176 | AES_256 -> 240
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.AES.AES_common_s.algorithm {a = Vale.AES.AES_common_s.AES_128 \/ a = Vale.AES.AES_common_s.AES_256} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Vale.AES.AES_common_s.AES_128", "Vale.AES.AES_common_s.AES_256", "Prims.int" ]
[]
false
false
false
false
false
let key_length (a: algorithm{a = AES_128 \/ a = AES_256}) =
match a with | AES_128 -> 16 | AES_256 -> 32
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.b128
val b128 : Type0
let b128 = buf_t TUInt8 TUInt128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 36, "start_col": 0, "start_line": 36 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Interop.Base.buf_t", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128" ]
[]
false
false
false
true
true
let b128 =
buf_t TUInt8 TUInt128
false
Vale.Stdcalls.X64.AesHash.fst
Vale.Stdcalls.X64.AesHash.key128_post
val key128_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
val key128_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom
let key128_post : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.AesHash.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 69, "start_col": 0, "start_line": 60 }
module Vale.Stdcalls.X64.AesHash open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GF = Vale.AES.X64.GF128_Init let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let dom: IX64.arity_ok_stdcall td = let y = [t128_no_mod; t128_mod] in assert_norm (List.length y = 2); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let key128_pre : (Ghost.erased (Seq.seq nat32)) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (c:V.va_code) (input_b:b128) (output_b:b128) (va_s0:V.va_state) -> GF.va_req_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b)
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GF128_Init.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.AesHash.fst" }
[ { "abbrev": true, "full_module": "Vale.AES.X64.GF128_Init", "short_module": "GF" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) -> Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.AesHash.dom
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_code", "Vale.Stdcalls.X64.AesHash.b128", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "Vale.AES.X64.GF128_Init.va_ens_Keyhash_init", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_128", "FStar.Ghost.reveal", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Prims.prop" ]
[]
false
false
false
true
false
let key128_post: (Ghost.erased (Seq.seq nat32)) -> VSig.vale_post dom =
fun (s: Ghost.erased (Seq.seq nat32)) (c: V.va_code) (input_b: b128) (output_b: b128) (va_s0: V.va_state) (va_s1: V.va_state) (f: V.va_fuel) -> GF.va_ens_Keyhash_init c va_s0 IA.win AES_128 (Ghost.reveal s) (as_vale_buffer input_b) (as_vale_buffer output_b) va_s1 f
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.length_aux2
val length_aux2 (b: uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0)
val length_aux2 (b: uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux2 (b:uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 29, "start_col": 0, "start_line": 25 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s unfold let uint8_p = B.buffer UInt8.t let length_aux (b:uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.Wrapper.X64.AES.uint8_p -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 240) (ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Wrapper.X64.AES.uint8_p", "LowStar.BufferView.Down.length_eq", "FStar.UInt8.t", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Arch.HeapTypes_s.TUInt8", "LowStar.Buffer.trivial_preorder", "Prims.unit", "Prims.b2t", "Prims.op_Equality", "Prims.int", "LowStar.Monotonic.Buffer.length", "Prims.squash", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let length_aux2 (b: uint8_p) : Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in DV.length_eq db
false
Vale.Wrapper.X64.AES.fsti
Vale.Wrapper.X64.AES.length_aux
val length_aux (b: uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0)
val length_aux (b: uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux (b:uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = let db = get_downview b in DV.length_eq db
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.AES.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 23, "start_col": 0, "start_line": 19 }
module Vale.Wrapper.X64.AES open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.Interop.Base open Vale.Def.Types_s unfold let uint8_p = B.buffer UInt8.t
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.AES.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.Wrapper.X64.AES.uint8_p -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 176) (ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Wrapper.X64.AES.uint8_p", "LowStar.BufferView.Down.length_eq", "FStar.UInt8.t", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "Vale.Arch.HeapTypes_s.TUInt8", "LowStar.Buffer.trivial_preorder", "Prims.unit", "Prims.b2t", "Prims.op_Equality", "Prims.int", "LowStar.Monotonic.Buffer.length", "Prims.squash", "Prims.op_Modulus", "LowStar.BufferView.Down.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let length_aux (b: uint8_p) : Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in DV.length_eq db
false
Pulse.Lib.HashTable.Spec.fst
Pulse.Lib.HashTable.Spec.lookup_spec
val lookup_spec (#k #v: _) (spec: spec_t k v) (key: k) : option v
val lookup_spec (#k #v: _) (spec: spec_t k v) (key: k) : option v
let lookup_spec #k #v (spec:spec_t k v) (key:k) : option v = spec key
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.HashTable.Spec.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 10, "end_line": 46, "start_col": 0, "start_line": 45 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Lib.HashTable.Spec module US = FStar.SizeT let unreachable #a (_:squash False) : a = coerce_eq () 42 open FStar.Ghost [@@ Pulse.Lib.Pervasives.Rust_derive "Clone"; Pulse.Lib.Pervasives.Rust_generics_bounds [["PartialEq"; "Copy"; "Clone"]; ["Clone"]] ] noeq type cell (kt : eqtype) (vt : Type) = | Clean | Zombie | Used : k:kt -> v:vt -> cell kt vt // noeq // type pht_sig = { // keyt : eqtype; // valt : Type0; // hashf : keyt -> nat; // } // Pure view of the hash table type spec_t (k:eqtype) v = k -> option v
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.HashTable.Spec.fst" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.HashTable", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
spec: Pulse.Lib.HashTable.Spec.spec_t k v -> key: k -> FStar.Pervasives.Native.option v
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Pulse.Lib.HashTable.Spec.spec_t", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let lookup_spec #k #v (spec: spec_t k v) (key: k) : option v =
spec key
false