effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.HyperStack.ST.ST | val read_sub_buffer (#a: Type0) (#rrel #rel: srel a) (b: mbuffer a rrel rel) (idx len: U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 -> live h0 b /\ U32.v len > 0 /\ U32.v idx + U32.v len <= length b)
(ensures
fun h0 s h1 -> h0 == h1 /\ s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) | val read_sub_buffer (#a: Type0) (#rrel #rel: srel a) (b: mbuffer a rrel rel) (idx len: U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 -> live h0 b /\ U32.v len > 0 /\ U32.v idx + U32.v len <= length b)
(ensures
fun h0 s h1 -> h0 == h1 /\ s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
let read_sub_buffer (#a: Type0) (#rrel #rel: srel a) (b: mbuffer a rrel rel) (idx len: U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 -> live h0 b /\ U32.v len > 0 /\ U32.v idx + U32.v len <= length b)
(ensures
fun h0 s h1 -> h0 == h1 /\ s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len)) = | true | null | false | let open HST in
let s = !(Buffer?.content b) in
let s = Seq.slice s (U32.v (Buffer?.idx b)) (U32.v (Buffer?.max_length b)) in
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.Seq.Base.slice",
"FStar.UInt32.v",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__idx",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__max_length",
"FStar.Seq.Properties.lseq",
"FStar.HyperStack.ST.op_Bang",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__content",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.eq2",
"LowStar.Monotonic.Buffer.as_seq"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\ | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_sub_buffer (#a: Type0) (#rrel #rel: srel a) (b: mbuffer a rrel rel) (idx len: U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 -> live h0 b /\ U32.v len > 0 /\ U32.v idx + U32.v len <= length b)
(ensures
fun h0 s h1 -> h0 == h1 /\ s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len)) | [] | LowStar.Monotonic.Buffer.read_sub_buffer | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> idx: FStar.UInt32.t -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST (FStar.Seq.Base.seq a) | {
"end_col": 51,
"end_line": 1499,
"start_col": 4,
"start_line": 1495
} |
FStar.HyperStack.ST.ST | val mgcmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ recallable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len))) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false | val mgcmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ recallable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len)))
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len = | true | null | false | alloc_heap_common r len (read_sub_buffer src id_src len) false | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.alloc_heap_common",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.Seq.Base.length",
"LowStar.Monotonic.Buffer.read_sub_buffer",
"Prims.l_and",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.recallable"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mgcmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ recallable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len))) | [] | LowStar.Monotonic.Buffer.mgcmalloc_and_blit | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
r: FStar.Monotonic.HyperHeap.rid ->
src: LowStar.Monotonic.Buffer.mbuffer a rrel1 rel1 ->
id_src: FStar.UInt32.t ->
len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)
{LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.recallable b}) | {
"end_col": 64,
"end_line": 1502,
"start_col": 2,
"start_line": 1502
} |
FStar.HyperStack.ST.StackInline | val malloca (#a:Type0) (#rrel:srel a)
(init:a) (len:U32.t)
:HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init) /\
frameOf b == HS.get_tip h0)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len) | val malloca (#a:Type0) (#rrel:srel a)
(init:a) (len:U32.t)
:HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init) /\
frameOf b == HS.get_tip h0))
let malloca #a #rrel init len = | true | null | false | lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.salloc",
"FStar.Seq.Base.create",
"FStar.HyperStack.ST.mstackref",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val malloca (#a:Type0) (#rrel:srel a)
(init:a) (len:U32.t)
:HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> alloca_pre len))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init) /\
frameOf b == HS.get_tip h0)) | [] | LowStar.Monotonic.Buffer.malloca | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | init: a -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.StackInline
(LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)) | {
"end_col": 41,
"end_line": 1515,
"start_col": 2,
"start_line": 1511
} |
FStar.HyperStack.ST.ST | val mmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ freeable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len))) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true | val mmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ freeable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len)))
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len = | true | null | false | alloc_heap_common r len (read_sub_buffer src id_src len) true | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.alloc_heap_common",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.Seq.Base.length",
"LowStar.Monotonic.Buffer.read_sub_buffer",
"Prims.l_and",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mmalloc_and_blit (#a:Type0) (#rrel:srel a) (r:HS.rid)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == r /\ freeable b})
(requires fun h0 ->
malloc_pre r len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len))) | [] | LowStar.Monotonic.Buffer.mmalloc_and_blit | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
r: FStar.Monotonic.HyperHeap.rid ->
src: LowStar.Monotonic.Buffer.mbuffer a rrel1 rel1 ->
id_src: FStar.UInt32.t ->
len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)
{LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.freeable b}) | {
"end_col": 63,
"end_line": 1508,
"start_col": 2,
"start_line": 1508
} |
FStar.HyperStack.ST.StackInline | val malloca_of_list (#a:Type0) (#rrel:srel a) (init: list a)
:HST.StackInline (lmbuffer a rrel rrel (normalize_term (List.Tot.length init)))
(requires (fun _ -> alloca_of_list_pre init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init) /\
frameOf b == HS.get_tip h0)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len) | val malloca_of_list (#a:Type0) (#rrel:srel a) (init: list a)
:HST.StackInline (lmbuffer a rrel rrel (normalize_term (List.Tot.length init)))
(requires (fun _ -> alloca_of_list_pre init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init) /\
frameOf b == HS.get_tip h0))
let malloca_of_list #a #rrel init = | true | null | false | let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"Prims.list",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.Pervasives.normalize_term",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.salloc",
"FStar.HyperStack.ST.mstackref",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.seq_of_list",
"FStar.UInt32.uint_to_t"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len) | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val malloca_of_list (#a:Type0) (#rrel:srel a) (init: list a)
:HST.StackInline (lmbuffer a rrel rrel (normalize_term (List.Tot.length init)))
(requires (fun _ -> alloca_of_list_pre init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init) /\
frameOf b == HS.get_tip h0)) | [] | LowStar.Monotonic.Buffer.malloca_of_list | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | init: Prims.list a
-> FStar.HyperStack.ST.StackInline
(LowStar.Monotonic.Buffer.lmbuffer a
rrel
rrel
(FStar.Pervasives.normalize_term (FStar.List.Tot.Base.length init))) | {
"end_col": 41,
"end_line": 1531,
"start_col": 35,
"start_line": 1524
} |
FStar.HyperStack.ST.StackInline | val malloca_and_blit (#a:Type0) (#rrel:srel a)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires fun h0 ->
alloca_pre len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len)) /\
frameOf b == HS.get_tip h0) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len) | val malloca_and_blit (#a:Type0) (#rrel:srel a)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires fun h0 ->
alloca_pre len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len)) /\
frameOf b == HS.get_tip h0)
let malloca_and_blit #a #rrel #_ #_ src id_src len = | true | null | false | lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.salloc",
"FStar.HyperStack.ST.mstackref",
"LowStar.Monotonic.Buffer.read_sub_buffer",
"FStar.Seq.Base.seq",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len) | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val malloca_and_blit (#a:Type0) (#rrel:srel a)
(#rrel1 #rel1:srel a) (src:mbuffer a rrel1 rel1) (id_src:U32.t) (len:U32.t)
: HST.StackInline (lmbuffer a rrel rrel (U32.v len))
(requires fun h0 ->
alloca_pre len /\
live h0 src /\ U32.v id_src + U32.v len <= length src)
(ensures fun h0 b h1 ->
alloc_post_mem_common b h0 h1
(Seq.slice (as_seq h0 src) (U32.v id_src) (U32.v id_src + U32.v len)) /\
frameOf b == HS.get_tip h0) | [] | LowStar.Monotonic.Buffer.malloca_and_blit | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | src: LowStar.Monotonic.Buffer.mbuffer a rrel1 rel1 -> id_src: FStar.UInt32.t -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.StackInline
(LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)) | {
"end_col": 41,
"end_line": 1522,
"start_col": 2,
"start_line": 1518
} |
FStar.HyperStack.ST.ST | val alloc_heap_common
(#a: Type0)
(#rrel: srel a)
(r: HST.erid)
(len: U32.t{U32.v len > 0})
(s: Seq.seq a {Seq.length s == U32.v len})
(mm: bool)
: HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\ Ghost.reveal (Buffer?.length b) == Buffer?.max_length b)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b | val alloc_heap_common
(#a: Type0)
(#rrel: srel a)
(r: HST.erid)
(len: U32.t{U32.v len > 0})
(s: Seq.seq a {Seq.length s == U32.v len})
(mm: bool)
: HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\ Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
let alloc_heap_common
(#a: Type0)
(#rrel: srel a)
(r: HST.erid)
(len: U32.t{U32.v len > 0})
(s: Seq.seq a {Seq.length s == U32.v len})
(mm: bool)
: HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\ Ghost.reveal (Buffer?.length b) == Buffer?.max_length b)) = | true | null | false | lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.HyperStack.ST.erid",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.UInt32.v",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"Prims.bool",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.ralloc_mm",
"FStar.HyperStack.ST.mmmref",
"FStar.HyperStack.ST.ralloc",
"FStar.HyperStack.ST.mref",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_True",
"Prims.l_and",
"LowStar.Monotonic.Buffer.alloc_post_mem_common",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"FStar.Monotonic.HyperStack.is_mm",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__max_length",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__content",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__idx",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__length"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\ | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val alloc_heap_common
(#a: Type0)
(#rrel: srel a)
(r: HST.erid)
(len: U32.t{U32.v len > 0})
(s: Seq.seq a {Seq.length s == U32.v len})
(mm: bool)
: HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures
(fun h0 b h1 ->
alloc_post_mem_common b h0 h1 s /\ frameOf b == r /\ HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\ Ghost.reveal (Buffer?.length b) == Buffer?.max_length b)) | [] | LowStar.Monotonic.Buffer.alloc_heap_common | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
r: FStar.HyperStack.ST.erid ->
len: FStar.UInt32.t{FStar.UInt32.v len > 0} ->
s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s == FStar.UInt32.v len} ->
mm: Prims.bool
-> FStar.HyperStack.ST.ST (LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)) | {
"end_col": 5,
"end_line": 1481,
"start_col": 4,
"start_line": 1476
} |
Prims.Tot | val cloc_cls: MG.cls abuffer | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cloc_cls =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.cls abuffer) cls | val cloc_cls: MG.cls abuffer
let cloc_cls = | false | null | false | assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.cls abuffer) cls | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [
"total"
] | [
"LowStar.Monotonic.Buffer.coerce",
"FStar.ModifiesGen.cls",
"LowStar.Monotonic.Buffer.abuffer",
"LowStar.Monotonic.Buffer.ubuffer",
"LowStar.Monotonic.Buffer.cls",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64"
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> ()
#push-options "--z3rlimit 128 --max_fuel 0 --max_ifuel 1 --initial_ifuel 1 --z3cliopt smt.qi.EAGER_THRESHOLD=4"
let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
= let open HST in
if len = 0ul then ()
else begin
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length)) 0 (U32.v len) s_src));
content := s_full';
let h' = HST.get () in
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.slice s' 0 (U32.v length)));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h //for modifies clause
end
#pop-options
let fill #t #rrel #rel b z len = fill' b z len
let abuffer' = ubuffer'
let coerce (t2: Type) (#t1: Type) (x1: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun y -> y == x1)) = x1 | false | true | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cloc_cls: MG.cls abuffer | [] | LowStar.Monotonic.Buffer.cloc_cls | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | FStar.ModifiesGen.cls LowStar.Monotonic.Buffer.abuffer | {
"end_col": 29,
"end_line": 1656,
"start_col": 2,
"start_line": 1655
} |
FStar.HyperStack.ST.ST | val mgcmalloc_of_list (#a:Type0) (#rrel:srel a) (r:HS.rid) (init:list a)
:HST.ST (b:lmbuffer a rrel rrel (normalize_term (List.Tot.length init)){frameOf b == r /\ recallable b})
(requires (fun _ -> gcmalloc_of_list_pre r init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init))) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len) | val mgcmalloc_of_list (#a:Type0) (#rrel:srel a) (r:HS.rid) (init:list a)
:HST.ST (b:lmbuffer a rrel rrel (normalize_term (List.Tot.length init)){frameOf b == r /\ recallable b})
(requires (fun _ -> gcmalloc_of_list_pre r init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init)))
let mgcmalloc_of_list #a #rrel r init = | true | null | false | let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.Monotonic.HyperHeap.rid",
"Prims.list",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.Pervasives.normalize_term",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Prims.l_and",
"Prims.eq2",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.recallable",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.ralloc",
"FStar.HyperStack.ST.mref",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Seq.Base.length",
"FStar.Seq.Properties.seq_of_list",
"FStar.UInt32.uint_to_t"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len) | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mgcmalloc_of_list (#a:Type0) (#rrel:srel a) (r:HS.rid) (init:list a)
:HST.ST (b:lmbuffer a rrel rrel (normalize_term (List.Tot.length init)){frameOf b == r /\ recallable b})
(requires (fun _ -> gcmalloc_of_list_pre r init))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.seq_of_list init))) | [] | LowStar.Monotonic.Buffer.mgcmalloc_of_list | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.Monotonic.HyperHeap.rid -> init: Prims.list a
-> FStar.HyperStack.ST.ST
(b:
LowStar.Monotonic.Buffer.lmbuffer a
rrel
rrel
(FStar.Pervasives.normalize_term (FStar.List.Tot.Base.length init))
{LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.recallable b}) | {
"end_col": 41,
"end_line": 1540,
"start_col": 39,
"start_line": 1533
} |
Prims.Tot | val cloc_of_loc (l: loc) : Tot (MG.loc cloc_cls) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cloc_of_loc l =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.loc cloc_cls) l | val cloc_of_loc (l: loc) : Tot (MG.loc cloc_cls)
let cloc_of_loc l = | false | null | false | assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.loc cloc_cls) l | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [
"total"
] | [
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.coerce",
"FStar.ModifiesGen.loc",
"LowStar.Monotonic.Buffer.abuffer",
"LowStar.Monotonic.Buffer.cloc_cls",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.ModifiesGen.cls",
"LowStar.Monotonic.Buffer.ubuffer"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64"
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> ()
#push-options "--z3rlimit 128 --max_fuel 0 --max_ifuel 1 --initial_ifuel 1 --z3cliopt smt.qi.EAGER_THRESHOLD=4"
let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
= let open HST in
if len = 0ul then ()
else begin
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length)) 0 (U32.v len) s_src));
content := s_full';
let h' = HST.get () in
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.slice s' 0 (U32.v length)));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h //for modifies clause
end
#pop-options
let fill #t #rrel #rel b z len = fill' b z len
let abuffer' = ubuffer'
let coerce (t2: Type) (#t1: Type) (x1: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun y -> y == x1)) = x1
let cloc_cls =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.cls abuffer) cls | false | true | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cloc_of_loc (l: loc) : Tot (MG.loc cloc_cls) | [] | LowStar.Monotonic.Buffer.cloc_of_loc | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: LowStar.Monotonic.Buffer.loc -> FStar.ModifiesGen.loc LowStar.Monotonic.Buffer.cloc_cls | {
"end_col": 28,
"end_line": 1660,
"start_col": 2,
"start_line": 1659
} |
Prims.Tot | val loc_of_cloc (l: MG.loc cloc_cls) : Tot loc | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let loc_of_cloc l =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce loc l | val loc_of_cloc (l: MG.loc cloc_cls) : Tot loc
let loc_of_cloc l = | false | null | false | assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce loc l | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [
"total"
] | [
"FStar.ModifiesGen.loc",
"LowStar.Monotonic.Buffer.abuffer",
"LowStar.Monotonic.Buffer.cloc_cls",
"LowStar.Monotonic.Buffer.coerce",
"LowStar.Monotonic.Buffer.loc",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.ModifiesGen.cls",
"LowStar.Monotonic.Buffer.ubuffer"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64"
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> ()
#push-options "--z3rlimit 128 --max_fuel 0 --max_ifuel 1 --initial_ifuel 1 --z3cliopt smt.qi.EAGER_THRESHOLD=4"
let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
= let open HST in
if len = 0ul then ()
else begin
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length)) 0 (U32.v len) s_src));
content := s_full';
let h' = HST.get () in
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.slice s' 0 (U32.v length)));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h //for modifies clause
end
#pop-options
let fill #t #rrel #rel b z len = fill' b z len
let abuffer' = ubuffer'
let coerce (t2: Type) (#t1: Type) (x1: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun y -> y == x1)) = x1
let cloc_cls =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.cls abuffer) cls
let cloc_of_loc l =
assert_norm (MG.cls abuffer == MG.cls ubuffer);
coerce (MG.loc cloc_cls) l | false | true | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val loc_of_cloc (l: MG.loc cloc_cls) : Tot loc | [] | LowStar.Monotonic.Buffer.loc_of_cloc | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: FStar.ModifiesGen.loc LowStar.Monotonic.Buffer.cloc_cls -> LowStar.Monotonic.Buffer.loc | {
"end_col": 14,
"end_line": 1664,
"start_col": 2,
"start_line": 1663
} |
FStar.HyperStack.ST.ST | val mmalloc_drgn_mm (#a:Type0) (#rrel:srel a)
(d:HST.drgn) (init:a) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == HST.rid_of_drgn d /\ freeable b})
(requires fun h -> alloc_drgn_pre h d len)
(ensures fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len | val mmalloc_drgn_mm (#a:Type0) (#rrel:srel a)
(d:HST.drgn) (init:a) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == HST.rid_of_drgn d /\ freeable b})
(requires fun h -> alloc_drgn_pre h d len)
(ensures fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init))
let mmalloc_drgn_mm #a #rrel d init len = | true | null | false | lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content:HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"FStar.HyperStack.ST.drgn",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.Buffer",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.lmbuffer",
"FStar.UInt32.v",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"FStar.HyperStack.ST.rid_of_drgn",
"LowStar.Monotonic.Buffer.freeable",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.HyperStack.ST.ralloc_drgn_mm",
"FStar.Seq.Base.create",
"Prims.unit",
"LowStar.Monotonic.Buffer.lemma_seq_sub_compatilibity_is_reflexive"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mmalloc_drgn_mm (#a:Type0) (#rrel:srel a)
(d:HST.drgn) (init:a) (len:U32.t)
: HST.ST (b:lmbuffer a rrel rrel (U32.v len){frameOf b == HST.rid_of_drgn d /\ freeable b})
(requires fun h -> alloc_drgn_pre h d len)
(ensures fun h0 b h1 -> alloc_post_mem_common b h0 h1 (Seq.create (U32.v len) init)) | [] | LowStar.Monotonic.Buffer.mmalloc_drgn_mm | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | d: FStar.HyperStack.ST.drgn -> init: a -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.ST
(b:
LowStar.Monotonic.Buffer.lmbuffer a rrel rrel (FStar.UInt32.v len)
{ LowStar.Monotonic.Buffer.frameOf b == FStar.HyperStack.ST.rid_of_drgn d /\
LowStar.Monotonic.Buffer.freeable b }) | {
"end_col": 28,
"end_line": 1554,
"start_col": 2,
"start_line": 1550
} |
FStar.HyperStack.ST.Stack | val fill (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) == Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) == Seq.slice (as_seq h0 b) (U32.v len) (length b)
)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fill #t #rrel #rel b z len = fill' b z len | val fill (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) == Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) == Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
let fill #t #rrel #rel b z len = | true | null | false | fill' b z len | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.fill'",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64"
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> ()
#push-options "--z3rlimit 128 --max_fuel 0 --max_ifuel 1 --initial_ifuel 1 --z3cliopt smt.qi.EAGER_THRESHOLD=4"
let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
= let open HST in
if len = 0ul then ()
else begin
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length)) 0 (U32.v len) s_src));
content := s_full';
let h' = HST.get () in
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.slice s' 0 (U32.v length)));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h //for modifies clause
end
#pop-options | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fill (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) == Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) == Seq.slice (as_seq h0 b) (U32.v len) (length b)
)) | [] | LowStar.Monotonic.Buffer.fill | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: LowStar.Monotonic.Buffer.mbuffer t rrel rel -> z: t -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 46,
"end_line": 1648,
"start_col": 33,
"start_line": 1648
} |
FStar.HyperStack.ST.Stack | val blit (#a:Type0) (#rrel1 #rrel2 #rel1 #rel2:srel a)
(src:mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst:mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
:HST.Stack unit (requires (fun h -> live h src /\ live h dst /\
U32.v idx_src + U32.v len <= length src /\
U32.v idx_dst + U32.v len <= length dst /\
(* TODO: remove the rhs part of this disjunction once patterns on loc_buffer_from_to are introduced *)
(loc_disjoint (loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) \/ disjoint src dst) /\
rel2 (as_seq h dst)
(Seq.replace_subseq (as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' -> modifies (loc_buffer dst) h h' /\
live h' dst /\
Seq.slice (as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) /\
Seq.slice (as_seq h' dst) 0 (U32.v idx_dst) ==
Seq.slice (as_seq h dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h' dst) (U32.v idx_dst + U32.v len) (length dst) ==
Seq.slice (as_seq h dst) (U32.v idx_dst + U32.v len) (length dst))) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> () | val blit (#a:Type0) (#rrel1 #rrel2 #rel1 #rel2:srel a)
(src:mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst:mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
:HST.Stack unit (requires (fun h -> live h src /\ live h dst /\
U32.v idx_src + U32.v len <= length src /\
U32.v idx_dst + U32.v len <= length dst /\
(* TODO: remove the rhs part of this disjunction once patterns on loc_buffer_from_to are introduced *)
(loc_disjoint (loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) \/ disjoint src dst) /\
rel2 (as_seq h dst)
(Seq.replace_subseq (as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' -> modifies (loc_buffer dst) h h' /\
live h' dst /\
Seq.slice (as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) /\
Seq.slice (as_seq h' dst) 0 (U32.v idx_dst) ==
Seq.slice (as_seq h dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h' dst) (U32.v idx_dst + U32.v len) (length dst) ==
Seq.slice (as_seq h dst) (U32.v idx_dst + U32.v len) (length dst)))
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len = | true | null | false | let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul
then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
assert (s_full2'
`Seq.equal`
(Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))));
content2 := s_full2';
let h1 = get () in
assert (s_full2'
`Seq.equal`
(Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.slice s2' 0 (U32.v length2))));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h
| _, _ -> () | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.Pervasives.Native.Mktuple2",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.Ghost.erased",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Ghost.reveal",
"Prims.op_Equality",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Prims.bool",
"LowStar.Monotonic.Buffer.g_upd_seq_as_seq",
"FStar.Seq.Base.slice",
"Prims._assert",
"Prims.eq2",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.g_upd_seq",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.replace_subseq",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.op_Colon_Equals",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.length",
"FStar.Seq.Base.seq",
"FStar.HyperStack.ST.op_Bang"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64" | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blit (#a:Type0) (#rrel1 #rrel2 #rel1 #rel2:srel a)
(src:mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst:mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
:HST.Stack unit (requires (fun h -> live h src /\ live h dst /\
U32.v idx_src + U32.v len <= length src /\
U32.v idx_dst + U32.v len <= length dst /\
(* TODO: remove the rhs part of this disjunction once patterns on loc_buffer_from_to are introduced *)
(loc_disjoint (loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) \/ disjoint src dst) /\
rel2 (as_seq h dst)
(Seq.replace_subseq (as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' -> modifies (loc_buffer dst) h h' /\
live h' dst /\
Seq.slice (as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) /\
Seq.slice (as_seq h' dst) 0 (U32.v idx_dst) ==
Seq.slice (as_seq h dst) 0 (U32.v idx_dst) /\
Seq.slice (as_seq h' dst) (U32.v idx_dst + U32.v len) (length dst) ==
Seq.slice (as_seq h dst) (U32.v idx_dst + U32.v len) (length dst))) | [] | LowStar.Monotonic.Buffer.blit | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
src: LowStar.Monotonic.Buffer.mbuffer a rrel1 rel1 ->
idx_src: FStar.UInt32.t ->
dst: LowStar.Monotonic.Buffer.mbuffer a rrel2 rel2 ->
idx_dst: FStar.UInt32.t ->
len: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 14,
"end_line": 1608,
"start_col": 2,
"start_line": 1565
} |
FStar.Pervasives.Lemma | val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h')) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
) | val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' = | false | null | true | let r0 = frameOf b in
let a0 = as_addr b in
let bb:ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0)))
h
h'
(loc_union l (loc_buffer b));
MG.modifies_strengthen l
#r0
#a0
(ubuffer_of_buffer_from_to b from to)
h
h'
(fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x
h
h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0:Seq.seq a = as_seq h b in
let _s1:Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let { b_max_length = ml ; b_offset = xoff ; b_length = xlen ; b_is_mm = is_mm } =
Ghost.reveal x
in
let { b_max_length = _ ; b_offset = b'off ; b_length = b'len } =
Ghost.reveal (ubuffer_of_buffer b')
in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat)
: Lemma (requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i)) =
let xi = xoff + i in
let bi:ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm })
in
assert (Seq.index xh i ==
Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i ==
Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then
(MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h')
else
if xi < from_
then
(assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
)
else
(assert (to_ <= xi);
assert (Seq.index xh i ==
Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i ==
Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_)))
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh'))) | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [
"lemma"
] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.loc",
"FStar.Monotonic.HyperStack.mem",
"FStar.ModifiesGen.modifies_strengthen",
"LowStar.Monotonic.Buffer.ubuffer",
"LowStar.Monotonic.Buffer.cls",
"LowStar.Monotonic.Buffer.ubuffer_of_buffer_from_to",
"FStar.Preorder.preorder",
"FStar.Monotonic.HyperStack.mreference",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperStack.frameOf",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Monotonic.HyperStack.as_addr",
"FStar.Monotonic.HyperStack.contains",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowStar.Monotonic.Buffer.ubuffer_preserved_intro",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__max_length",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__content",
"Prims.nat",
"Prims.bool",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"FStar.Classical.move_requires",
"Prims.op_BarBar",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"FStar.ModifiesGen.modifies_aloc_elim",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Monotonic.Buffer.loc_disjoint",
"FStar.ModifiesGen.loc_disjoint_aloc_intro",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"LowStar.Monotonic.Buffer.loc_disjoint_includes",
"FStar.ModifiesGen.loc_of_aloc",
"FStar.ModifiesGen.loc_includes_aloc",
"FStar.ModifiesGen.loc",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.ubuffer'",
"LowStar.Monotonic.Buffer.Mkubuffer_",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.as_addr",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.ubuffer_of_buffer",
"FStar.UInt.uint_t",
"LowStar.Monotonic.Buffer.__proj__Buffer__item__idx",
"LowStar.Monotonic.Buffer.lemma_equal_instances_implies_equal_types",
"FStar.Pervasives.coerce_eq",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_mm",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_preorders",
"LowStar.Monotonic.Buffer.modifies_loc_includes",
"LowStar.Monotonic.Buffer.loc_addresses",
"FStar.Set.singleton"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16" | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h')) | [] | LowStar.Monotonic.Buffer.modifies_loc_buffer_from_to_intro' | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
from: FStar.UInt32.t ->
to: FStar.UInt32.t ->
l: LowStar.Monotonic.Buffer.loc ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
(let s = LowStar.Monotonic.Buffer.as_seq h b in
let s' = LowStar.Monotonic.Buffer.as_seq h' b in
Prims.op_Negation (LowStar.Monotonic.Buffer.g_is_null b) /\
LowStar.Monotonic.Buffer.live h b /\
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_union l
(LowStar.Monotonic.Buffer.loc_buffer b))
h
h' /\ FStar.UInt32.v from <= FStar.UInt32.v to /\
FStar.UInt32.v to <= LowStar.Monotonic.Buffer.length b /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 (FStar.UInt32.v from))
(FStar.Seq.Base.slice s' 0 (FStar.UInt32.v from)) /\
FStar.Seq.Base.equal (FStar.Seq.Base.slice s
(FStar.UInt32.v to)
(LowStar.Monotonic.Buffer.length b))
(FStar.Seq.Base.slice s' (FStar.UInt32.v to) (LowStar.Monotonic.Buffer.length b))))
(ensures
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_union l
(LowStar.Monotonic.Buffer.loc_buffer_from_to b from to))
h
h') | {
"end_col": 3,
"end_line": 1188,
"start_col": 71,
"start_line": 1132
} |
FStar.Pervasives.Lemma | val g_upd_modifies_strong (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel)
(i:nat{i < length b})
(v:a)
(h:HS.mem{live h b})
: Lemma (modifies (loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + 1))) h (g_upd b i v h)) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h' | val g_upd_modifies_strong (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel)
(i:nat{i < length b})
(v:a)
(h:HS.mem{live h b})
: Lemma (modifies (loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + 1))) h (g_upd b i v h))
let g_upd_modifies_strong #_ #_ #_ b i v h = | false | null | true | let h' = g_upd b i v h in
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h' | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [
"lemma"
] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.Monotonic.Buffer.length",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.modifies_1_from_to_modifies",
"FStar.UInt32.uint_to_t",
"Prims.op_Addition",
"Prims.unit",
"LowStar.Monotonic.Buffer.s_lemma_equal_instances_implies_equal_types",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_mm",
"FStar.Monotonic.Heap.lemma_distinct_addrs_distinct_preorders",
"LowStar.Monotonic.Buffer.g_upd"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 48,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val g_upd_modifies_strong (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel)
(i:nat{i < length b})
(v:a)
(h:HS.mem{live h b})
: Lemma (modifies (loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + 1))) h (g_upd b i v h)) | [] | LowStar.Monotonic.Buffer.g_upd_modifies_strong | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
i: Prims.nat{i < LowStar.Monotonic.Buffer.length b} ->
v: a ->
h: FStar.Monotonic.HyperStack.mem{LowStar.Monotonic.Buffer.live h b}
-> FStar.Pervasives.Lemma
(ensures
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer_from_to b
(FStar.UInt32.uint_to_t i)
(FStar.UInt32.uint_to_t (i + 1)))
h
(LowStar.Monotonic.Buffer.g_upd b i v h)) | {
"end_col": 80,
"end_line": 1345,
"start_col": 44,
"start_line": 1339
} |
FStar.HyperStack.ST.Stack | val fill' (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) (z: t) (len: U32.t)
: HST.Stack unit
(requires
(fun h ->
live h b /\ U32.v len <= length b /\
rel (as_seq h b)
(Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
(Seq.slice (as_seq h1 b) 0 (U32.v len)) `Seq.equal` (Seq.create (U32.v len) z) /\
(Seq.slice (as_seq h1 b) (U32.v len) (length b))
`Seq.equal`
(Seq.slice (as_seq h0 b) (U32.v len) (length b)))) | [
{
"abbrev": true,
"full_module": "FStar.ModifiesGen",
"short_module": "MG"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b)
))
= let open HST in
if len = 0ul then ()
else begin
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length)) 0 (U32.v len) s_src));
content := s_full';
let h' = HST.get () in
assert (s_full' `Seq.equal` Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v length) (Seq.slice s' 0 (U32.v length)));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h //for modifies clause
end | val fill' (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) (z: t) (len: U32.t)
: HST.Stack unit
(requires
(fun h ->
live h b /\ U32.v len <= length b /\
rel (as_seq h b)
(Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
(Seq.slice (as_seq h1 b) 0 (U32.v len)) `Seq.equal` (Seq.create (U32.v len) z) /\
(Seq.slice (as_seq h1 b) (U32.v len) (length b))
`Seq.equal`
(Seq.slice (as_seq h0 b) (U32.v len) (length b))))
let fill' (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) (z: t) (len: U32.t)
: HST.Stack unit
(requires
(fun h ->
live h b /\ U32.v len <= length b /\
rel (as_seq h b)
(Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
(Seq.slice (as_seq h1 b) 0 (U32.v len)) `Seq.equal` (Seq.create (U32.v len) z) /\
(Seq.slice (as_seq h1 b) (U32.v len) (length b))
`Seq.equal`
(Seq.slice (as_seq h0 b) (U32.v len) (length b)))) = | true | null | false | let open HST in
if len = 0ul
then ()
else
let h = get () in
let Buffer max_length content idx length = b in
let s_full = !content in
let s = Seq.slice s_full (U32.v idx) (U32.v max_length) in
let s_src = Seq.create (U32.v len) z in
let s' = Seq.replace_subseq s 0 (U32.v len) s_src in
let s_full' = Seq.replace_subseq s_full (U32.v idx) (U32.v idx + U32.v len) s_src in
assert (s_full'
`Seq.equal`
(Seq.replace_subseq s_full
(U32.v idx)
(U32.v idx + U32.v length)
(Seq.replace_subseq (Seq.slice s_full (U32.v idx) (U32.v idx + U32.v length))
0
(U32.v len)
s_src)));
content := s_full';
let h' = HST.get () in
assert (s_full'
`Seq.equal`
(Seq.replace_subseq s_full
(U32.v idx)
(U32.v idx + U32.v length)
(Seq.slice s' 0 (U32.v length))));
assert (h' == g_upd_seq b (Seq.slice s' 0 (U32.v length)) h);
g_upd_seq_as_seq b (Seq.slice s' 0 (U32.v length)) h | {
"checked_file": "LowStar.Monotonic.Buffer.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.ModifiesGen.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowStar.Monotonic.Buffer.fst"
} | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"Prims.op_Equality",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Prims.bool",
"FStar.HyperStack.ST.mreference",
"FStar.Seq.Properties.lseq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.srel_to_lsrel",
"FStar.Ghost.erased",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.g_upd_seq_as_seq",
"FStar.Seq.Base.slice",
"Prims._assert",
"Prims.eq2",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.g_upd_seq",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.replace_subseq",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.op_Colon_Equals",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"FStar.HyperStack.ST.op_Bang",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
private let srel_to_lsrel (#a:Type0) (len:nat) (pre:srel a) :P.preorder (Seq.lseq a len) = pre
(*
* Counterpart of compatible_sub from the fsti but using sequences
*
* The patterns are guarded tightly, the proof of transitivity gets quite flaky otherwise
* The cost is that we have to additional asserts as triggers
*)
let compatible_sub_preorder (#a:Type0)
(len:nat) (rel:srel a) (i:nat) (j:nat{i <= j /\ j <= len}) (sub_rel:srel a)
= compatible_subseq_preorder len rel i j sub_rel
(*
* Reflexivity of the compatibility relation
*)
let lemma_seq_sub_compatilibity_is_reflexive (#a:Type0) (len:nat) (rel:srel a)
:Lemma (compatible_sub_preorder len rel 0 len rel)
= assert (forall (s1 s2:Seq.seq a). Seq.length s1 == Seq.length s2 ==>
Seq.equal (Seq.replace_subseq s1 0 (Seq.length s1) s2) s2)
(*
* Transitivity of the compatibility relation
*
* i2 and j2 are relative offsets within [i1, j1) (i.e. assuming i1 = 0)
*)
let lemma_seq_sub_compatibility_is_transitive (#a:Type0)
(len:nat) (rel:srel a) (i1 j1:nat) (rel1:srel a) (i2 j2:nat) (rel2:srel a)
:Lemma (requires (i1 <= j1 /\ j1 <= len /\ i2 <= j2 /\ j2 <= j1 - i1 /\
compatible_sub_preorder len rel i1 j1 rel1 /\
compatible_sub_preorder (j1 - i1) rel1 i2 j2 rel2))
(ensures (compatible_sub_preorder len rel (i1 + i2) (i1 + j2) rel2))
= let t1 (s1 s2:Seq.seq a) = Seq.length s1 == len /\ Seq.length s2 == len /\ rel s1 s2 in
let t2 (s1 s2:Seq.seq a) = t1 s1 s2 /\ rel2 (Seq.slice s1 (i1 + i2) (i1 + j2)) (Seq.slice s2 (i1 + i2) (i1 + j2)) in
let aux0 (s1 s2:Seq.seq a) :Lemma (t1 s1 s2 ==> t2 s1 s2)
= Classical.arrow_to_impl #(t1 s1 s2) #(t2 s1 s2)
(fun _ ->
assert (rel1 (Seq.slice s1 i1 j1) (Seq.slice s2 i1 j1));
assert (rel2 (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice (Seq.slice s2 i1 j1) i2 j2));
assert (Seq.equal (Seq.slice (Seq.slice s1 i1 j1) i2 j2) (Seq.slice s1 (i1 + i2) (i1 + j2)));
assert (Seq.equal (Seq.slice (Seq.slice s2 i1 j1) i2 j2) (Seq.slice s2 (i1 + i2) (i1 + j2))))
in
let t1 (s s2:Seq.seq a) = Seq.length s == len /\ Seq.length s2 == j2 - i2 /\
rel2 (Seq.slice s (i1 + i2) (i1 + j2)) s2 in
let t2 (s s2:Seq.seq a) = t1 s s2 /\ rel s (Seq.replace_subseq s (i1 + i2) (i1 + j2) s2) in
let aux1 (s s2:Seq.seq a) :Lemma (t1 s s2 ==> t2 s s2)
= Classical.arrow_to_impl #(t1 s s2) #(t2 s s2)
(fun _ ->
assert (Seq.equal (Seq.slice s (i1 + i2) (i1 + j2)) (Seq.slice (Seq.slice s i1 j1) i2 j2));
assert (rel1 (Seq.slice s i1 j1) (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2));
assert (rel s (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2)));
assert (Seq.equal (Seq.replace_subseq s i1 j1 (Seq.replace_subseq (Seq.slice s i1 j1) i2 j2 s2))
(Seq.replace_subseq s (i1 + i2) (i1 + j2) s2)))
in
Classical.forall_intro_2 aux0; Classical.forall_intro_2 aux1
noeq type mbuffer (a:Type0) (rrel:srel a) (rel:srel a) :Type0 =
| Null
| Buffer:
max_length:U32.t ->
content:HST.mreference (Seq.lseq a (U32.v max_length)) (srel_to_lsrel (U32.v max_length) rrel) ->
idx:U32.t ->
length:Ghost.erased U32.t{U32.v idx + U32.v (Ghost.reveal length) <= U32.v max_length} ->
mbuffer a rrel rel
let g_is_null #_ #_ #_ b = Null? b
let mnull #_ #_ #_ = Null
let null_unique #_ #_ #_ _ = ()
let unused_in #_ #_ #_ b h =
match b with
| Null -> False
| Buffer _ content _ _ -> content `HS.unused_in` h
let buffer_compatible (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) : GTot Type0 =
match b with
| Null -> True
| Buffer max_length content idx length ->
compatible_sub_preorder (U32.v max_length) rrel
(U32.v idx) (U32.v idx + U32.v length) rel //proof of compatibility
let live #_ #rrel #rel h b =
match b with
| Null -> True
| Buffer max_length content idx length ->
h `HS.contains` content /\
buffer_compatible b
let live_null _ _ _ _ = ()
let live_not_unused_in #_ #_ #_ _ _ = ()
let lemma_live_equal_mem_domains #_ #_ #_ _ _ _ = ()
let frameOf #_ #_ #_ b = if Null? b then HS.root else HS.frameOf (Buffer?.content b)
let as_addr #_ #_ #_ b = if g_is_null b then 0 else HS.as_addr (Buffer?.content b)
let unused_in_equiv #_ #_ #_ b h =
if g_is_null b then Heap.not_addr_unused_in_nullptr (Map.sel (HS.get_hmap h) HS.root) else ()
let live_region_frameOf #_ #_ #_ _ _ = ()
let len #_ #_ #_ b =
match b with
| Null -> 0ul
| Buffer _ _ _ len -> len
let len_null a _ _ = ()
let as_seq #_ #_ #_ h b =
match b with
| Null -> Seq.empty
| Buffer max_len content idx len ->
Seq.slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len)
let length_as_seq #_ #_ #_ _ _ = ()
let mbuffer_injectivity_in_first_preorder () = ()
let mgsub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content idx length ->
Buffer max_len content (U32.add idx i) (Ghost.hide len)
let live_gsub #_ #rrel #rel _ b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
let prf () : Lemma
(requires (buffer_compatible b))
(ensures (buffer_compatible (mgsub sub_rel b i len)))
=
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
in
Classical.move_requires prf ()
let gsub_is_null #_ #_ #_ _ _ _ _ = ()
let len_gsub #_ #_ #_ _ _ _ _ = ()
let frameOf_gsub #_ #_ #_ _ _ _ _ = ()
let as_addr_gsub #_ #_ #_ _ _ _ _ = ()
let mgsub_inj #_ #_ #_ _ _ _ _ _ _ _ _ = ()
#push-options "--z3rlimit 20"
let gsub_gsub #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let prf () : Lemma
(requires (compatible_sub b i1 len1 sub_rel1 /\ compatible_sub (mgsub sub_rel1 b i1 len1) i2 len2 sub_rel2))
(ensures (compatible_sub b (U32.add i1 i2) len2 sub_rel2))
=
lemma_seq_sub_compatibility_is_transitive (length b) rel (U32.v i1) (U32.v i1 + U32.v len1) sub_rel1
(U32.v i2) (U32.v i2 + U32.v len2) sub_rel2
in
Classical.move_requires prf ()
#pop-options
/// A buffer ``b`` is equal to its "largest" sub-buffer, at index 0 and
/// length ``len b``.
let gsub_zero_length #_ #_ #rel b = lemma_seq_sub_compatilibity_is_reflexive (length b) rel
let as_seq_gsub #_ #_ #_ h b i len _ =
match b with
| Null -> ()
| Buffer _ content idx len0 ->
Seq.slice_slice (HS.sel h content) (U32.v idx) (U32.v idx + U32.v len0) (U32.v i) (U32.v i + U32.v len)
let lemma_equal_instances_implies_equal_types (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b)
: Lemma (requires s1 === s2)
(ensures a == b)
= Seq.lemma_equal_instances_implies_equal_types ()
let s_lemma_equal_instances_implies_equal_types (_:unit)
: Lemma (forall (a:Type) (b:Type) (s1:Seq.seq a) (s2:Seq.seq b).
{:pattern (has_type s1 (Seq.seq a));
(has_type s2 (Seq.seq b)) }
s1 === s2 ==> a == b)
= Seq.lemma_equal_instances_implies_equal_types()
let live_same_addresses_equal_types_and_preorders'
(#a1 #a2: Type0)
(#rrel1 #rel1: srel a1)
(#rrel2 #rel2: srel a2)
(b1: mbuffer a1 rrel1 rel1)
(b2: mbuffer a2 rrel2 rel2)
(h: HS.mem)
: Lemma
(requires
frameOf b1 == frameOf b2 /\
as_addr b1 == as_addr b2 /\
live h b1 /\
live h b2 /\
(~ (g_is_null b1 /\ g_is_null b2)))
(ensures
a1 == a2 /\
rrel1 == rrel2)
= Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
let s1 : Seq.seq a1 = as_seq h b1 in
assert (Seq.seq a1 == Seq.seq a2);
let s1' : Seq.seq a2 = coerce_eq _ s1 in
assert (s1 === s1');
lemma_equal_instances_implies_equal_types a1 a2 s1 s1'
let live_same_addresses_equal_types_and_preorders
#_ #_ #_ #_ #_ #_ b1 b2 h
= Classical.move_requires (live_same_addresses_equal_types_and_preorders' b1 b2) h
(* Untyped view of buffers, used only to implement the generic modifies clause. DO NOT USE in client code. *)
noeq
type ubuffer_
: Type0
= {
b_max_length: nat;
b_offset: nat;
b_length: nat;
b_is_mm: bool;
}
val ubuffer' (region: HS.rid) (addr: nat) : Tot Type0
let ubuffer' region addr = (x: ubuffer_ { x.b_offset + x.b_length <= x.b_max_length } )
let ubuffer (region: HS.rid) (addr: nat) : Tot Type0 = G.erased (ubuffer' region addr)
let ubuffer_of_buffer' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel)
:Tot (ubuffer (frameOf b) (as_addr b))
= if Null? b
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
Ghost.hide ({
b_max_length = U32.v (Buffer?.max_length b);
b_offset = U32.v (Buffer?.idx b);
b_length = U32.v (Buffer?.length b);
b_is_mm = HS.is_mm (Buffer?.content b);
})
let ubuffer_preserved'
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h h' : HS.mem)
: GTot Type0
= forall (t':Type0) (rrel rel:srel t') (b':mbuffer t' rrel rel) .
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
val ubuffer_preserved (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h h' : HS.mem) : GTot Type0
let ubuffer_preserved = ubuffer_preserved'
let ubuffer_preserved_intro
(#r:HS.rid)
(#a:nat)
(b:ubuffer r a)
(h h' :HS.mem)
(f0: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (frameOf b' == r /\ as_addr b' == a /\ live h b'))
(ensures (live h' b'))
))
(f: (
(t':Type0) ->
(rrel:srel t') -> (rel:srel t') ->
(b':mbuffer t' rrel rel) ->
Lemma
(requires (
frameOf b' == r /\ as_addr b' == a /\
live h b' /\ live h' b' /\
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
))))
(ensures (
Buffer? b' /\ (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len /\
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))
))
: Lemma
(ubuffer_preserved b h h')
= let g'
(t':Type0) (rrel rel:srel t')
(b':mbuffer t' rrel rel)
: Lemma
((frameOf b' == r /\ as_addr b' == a) ==> (
(live h b' ==> live h' b') /\ (
((live h b' /\ live h' b' /\ Buffer? b') ==> (
let ({ b_max_length = bmax; b_offset = boff; b_length = blen }) = Ghost.reveal b in
let Buffer max _ idx len = b' in (
U32.v max == bmax /\
U32.v idx <= boff /\
boff + blen <= U32.v idx + U32.v len
) ==>
Seq.equal (Seq.slice (as_seq h b') (boff - U32.v idx) (boff - U32.v idx + blen)) (Seq.slice (as_seq h' b') (boff - U32.v idx) (boff - U32.v idx + blen))
)))))
= Classical.move_requires (f0 t' rrel rel) b';
Classical.move_requires (f t' rrel rel) b'
in
Classical.forall_intro_4 g'
val ubuffer_preserved_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h : HS.mem) : Lemma
(ubuffer_preserved b h h)
let ubuffer_preserved_refl #r #a b h = ()
val ubuffer_preserved_trans (#r: HS.rid) (#a: nat) (b: ubuffer r a) (h1 h2 h3 : HS.mem) : Lemma
(requires (ubuffer_preserved b h1 h2 /\ ubuffer_preserved b h2 h3))
(ensures (ubuffer_preserved b h1 h3))
let ubuffer_preserved_trans #r #a b h1 h2 h3 = ()
val same_mreference_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
(f: (
(a' : Type) ->
(pre: Preorder.preorder a') ->
(r': HS.mreference a' pre) ->
Lemma
(requires (h1 `HS.contains` r' /\ r == HS.frameOf r' /\ a == HS.as_addr r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
))
: Lemma
(ubuffer_preserved b h1 h2)
let same_mreference_ubuffer_preserved #r #a b h1 h2 f =
ubuffer_preserved_intro b h1 h2
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
(fun t' _ _ b' ->
if Null? b'
then ()
else
f _ _ (Buffer?.content b')
)
val addr_unused_in_ubuffer_preserved
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (HS.live_region h1 r ==> a `Heap.addr_unused_in` (Map.sel (HS.get_hmap h1) r)))
(ensures (ubuffer_preserved b h1 h2))
let addr_unused_in_ubuffer_preserved #r #a b h1 h2 = ()
val ubuffer_of_buffer (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) :Tot (ubuffer (frameOf b) (as_addr b))
let ubuffer_of_buffer #_ #_ #_ b = ubuffer_of_buffer' b
let ubuffer_of_buffer_from_to_none_cond
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot bool
= g_is_null b || U32.v to < U32.v from || U32.v from > length b
let ubuffer_of_buffer_from_to
#a #rrel #rel (b: mbuffer a rrel rel) from to
: GTot (ubuffer (frameOf b) (as_addr b))
= if ubuffer_of_buffer_from_to_none_cond b from to
then
Ghost.hide ({
b_max_length = 0;
b_offset = 0;
b_length = 0;
b_is_mm = false;
})
else
let to' = if U32.v to > length b then length b else U32.v to in
let b1 = ubuffer_of_buffer b in
Ghost.hide ({ Ghost.reveal b1 with b_offset = (Ghost.reveal b1).b_offset + U32.v from; b_length = to' - U32.v from })
val ubuffer_preserved_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h h':HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h' /\ live h b))
(ensures (live h' b /\ as_seq h b == as_seq h' b))
let ubuffer_preserved_elim #_ #_ #_ _ _ _ = ()
val ubuffer_preserved_from_to_elim (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h h' : HS.mem)
:Lemma (requires (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) h h' /\ live h b))
(ensures (live h' b /\ ((U32.v from <= U32.v to /\ U32.v to <= length b) ==> Seq.slice (as_seq h b) (U32.v from) (U32.v to) == Seq.slice (as_seq h' b) (U32.v from) (U32.v to))))
let ubuffer_preserved_from_to_elim #_ #_ #_ _ _ _ _ _ = ()
let unused_in_ubuffer_preserved (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h h':HS.mem)
: Lemma (requires (b `unused_in` h))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'))
= Classical.move_requires (fun b -> live_not_unused_in h b) b;
live_null a rrel rel h;
null_unique b;
unused_in_equiv b h;
addr_unused_in_ubuffer_preserved #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) h h'
let ubuffer_includes' (larger smaller: ubuffer_) : GTot Type0 =
larger.b_is_mm == smaller.b_is_mm /\
larger.b_max_length == smaller.b_max_length /\
larger.b_offset <= smaller.b_offset /\
smaller.b_offset + smaller.b_length <= larger.b_offset + larger.b_length
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_includes0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (larger:ubuffer r1 a1) (smaller:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\ ubuffer_includes' (G.reveal larger) (G.reveal smaller)
val ubuffer_includes (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) : GTot Type0
let ubuffer_includes #r #a larger smaller = ubuffer_includes0 larger smaller
val ubuffer_includes_refl (#r: HS.rid) (#a: nat) (b: ubuffer r a) : Lemma
(b `ubuffer_includes` b)
let ubuffer_includes_refl #r #a b = ()
val ubuffer_includes_trans (#r: HS.rid) (#a: nat) (b1 b2 b3: ubuffer r a) : Lemma
(requires (b1 `ubuffer_includes` b2 /\ b2 `ubuffer_includes` b3))
(ensures (b1 `ubuffer_includes` b3))
let ubuffer_includes_trans #r #a b1 b2 b3 = ()
(*
* TODO: not sure how to make this lemma work with preorders
* it creates a buffer larger' in the proof
* we need a compatible preorder for that
* may be take that as an argument?
*)
(*val ubuffer_includes_ubuffer_preserved (#r: HS.rid) (#a: nat) (larger smaller: ubuffer r a) (h1 h2: HS.mem) : Lemma
(requires (larger `ubuffer_includes` smaller /\ ubuffer_preserved larger h1 h2))
(ensures (ubuffer_preserved smaller h1 h2))
let ubuffer_includes_ubuffer_preserved #r #a larger smaller h1 h2 =
ubuffer_preserved_intro smaller h1 h2 (fun t' b' ->
if Null? b'
then ()
else
let (Buffer max_len content idx' len') = b' in
let idx = U32.uint_to_t (G.reveal larger).b_offset in
let len = U32.uint_to_t (G.reveal larger).b_length in
let larger' = Buffer max_len content idx len in
assert (b' == gsub larger' (U32.sub idx' idx) len');
ubuffer_preserved_elim larger' h1 h2
)*)
let ubuffer_disjoint' (x1 x2: ubuffer_) : GTot Type0 =
if x1.b_length = 0 || x2.b_length = 0
then True
else
(x1.b_max_length == x2.b_max_length /\
(x1.b_offset + x1.b_length <= x2.b_offset \/
x2.b_offset + x2.b_length <= x1.b_offset))
(* TODO: added this because of #606, now that it is fixed, we may not need it anymore *)
let ubuffer_disjoint0 (#r1 #r2:HS.rid) (#a1 #a2:nat) (b1:ubuffer r1 a1) (b2:ubuffer r2 a2) =
r1 == r2 /\ a1 == a2 /\
ubuffer_disjoint' (G.reveal b1) (G.reveal b2)
val ubuffer_disjoint (#r:HS.rid) (#a:nat) (b1 b2:ubuffer r a) :GTot Type0
let ubuffer_disjoint #r #a b1 b2 = ubuffer_disjoint0 b1 b2
val ubuffer_disjoint_sym (#r:HS.rid) (#a: nat) (b1 b2:ubuffer r a)
:Lemma (ubuffer_disjoint b1 b2 <==> ubuffer_disjoint b2 b1)
let ubuffer_disjoint_sym #_ #_ b1 b2 = ()
val ubuffer_disjoint_includes (#r: HS.rid) (#a: nat) (larger1 larger2: ubuffer r a) (smaller1 smaller2: ubuffer r a) : Lemma
(requires (ubuffer_disjoint larger1 larger2 /\ larger1 `ubuffer_includes` smaller1 /\ larger2 `ubuffer_includes` smaller2))
(ensures (ubuffer_disjoint smaller1 smaller2))
let ubuffer_disjoint_includes #r #a larger1 larger2 smaller1 smaller2 = ()
val liveness_preservation_intro (#a:Type0) (#rrel:srel a) (#rel:srel a)
(h h':HS.mem) (b:mbuffer a rrel rel)
(f: (
(t':Type0) ->
(pre: Preorder.preorder t') ->
(r: HS.mreference t' pre) ->
Lemma
(requires (HS.frameOf r == frameOf b /\ HS.as_addr r == as_addr b /\ h `HS.contains` r))
(ensures (h' `HS.contains` r))
))
:Lemma (requires (live h b)) (ensures (live h' b))
let liveness_preservation_intro #_ #_ #_ _ _ b f =
if Null? b
then ()
else f _ _ (Buffer?.content b)
(* Basic, non-compositional modifies clauses, used only to implement the generic modifies clause. DO NOT USE in client code *)
let modifies_0_preserves_mreferences (h1 h2: HS.mem) : GTot Type0 =
forall (a: Type) (pre: Preorder.preorder a) (r: HS.mreference a pre) .
h1 `HS.contains` r ==> (h2 `HS.contains` r /\ HS.sel h1 r == HS.sel h2 r)
let modifies_0_preserves_regions (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) . HS.live_region h1 r ==> HS.live_region h2 r
let modifies_0_preserves_not_unused_in (h1 h2: HS.mem) : GTot Type0 =
forall (r: HS.rid) (n: nat) . (
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
) ==> (
n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)
)
let modifies_0' (h1 h2: HS.mem) : GTot Type0 =
modifies_0_preserves_mreferences h1 h2 /\
modifies_0_preserves_regions h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2
val modifies_0 (h1 h2: HS.mem) : GTot Type0
let modifies_0 = modifies_0'
val modifies_0_live_region (h1 h2: HS.mem) (r: HS.rid) : Lemma
(requires (modifies_0 h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_0_live_region h1 h2 r = ()
val modifies_0_mreference (#a: Type) (#pre: Preorder.preorder a) (h1 h2: HS.mem) (r: HS.mreference a pre) : Lemma
(requires (modifies_0 h1 h2 /\ h1 `HS.contains` r))
(ensures (h2 `HS.contains` r /\ h1 `HS.sel` r == h2 `HS.sel` r))
let modifies_0_mreference #a #pre h1 h2 r = ()
let modifies_0_ubuffer
(#r: HS.rid)
(#a: nat)
(b: ubuffer r a)
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (ubuffer_preserved b h1 h2))
= same_mreference_ubuffer_preserved b h1 h2 (fun a' pre r' -> modifies_0_mreference h1 h2 r')
val modifies_0_unused_in
(h1 h2: HS.mem)
(r: HS.rid)
(n: nat)
: Lemma
(requires (
modifies_0 h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)
))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_0_unused_in h1 h2 r n = ()
let modifies_1_preserves_mreferences (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre).
((frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r') ==>
(h2 `HS.contains` r' /\ HS.sel h1 r' == HS.sel h2 r')
let modifies_1_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_from_to_preserves_ubuffers (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= forall (b':ubuffer (frameOf b) (as_addr b)).
(ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b') ==> ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2
let modifies_1_preserves_livenesses (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= forall (a':Type) (pre:Preorder.preorder a') (r':HS.mreference a' pre). h1 `HS.contains` r' ==> h2 `HS.contains` r'
let modifies_1' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
: GTot Type0
= modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_preserves_ubuffers b h1 h2
val modifies_1 (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_1 = modifies_1'
let modifies_1_from_to (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
: GTot Type0
= if ubuffer_of_buffer_from_to_none_cond b from to
then modifies_0 h1 h2
else
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_1_preserves_livenesses b h1 h2 /\
modifies_0_preserves_not_unused_in h1 h2 /\
modifies_1_from_to_preserves_ubuffers b from to h1 h2
val modifies_1_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1 b h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
let modifies_1_live_region #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ HS.live_region h1 r)) (ensures (HS.live_region h2 r))
= ()
val modifies_1_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1 b h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
let modifies_1_liveness #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_liveness
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\ h1 `HS.contains` r')) (ensures (h2 `HS.contains` r'))
= ()
val modifies_1_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1 b h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_1_unused_in #_ #_ #_ _ _ _ _ _ = ()
let modifies_1_from_to_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
:Lemma (requires (modifies_1_from_to b from to h1 h2 /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
= ()
val modifies_1_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1 b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_1_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
let modifies_1_from_to_mreference
(#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r': HS.mreference a' pre)
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
= ()
val modifies_1_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1 b h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
let modifies_1_ubuffer #_ #_ #_ _ _ _ _ = ()
let modifies_1_from_to_ubuffer (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem) (b':ubuffer (frameOf b) (as_addr b))
: Lemma (requires (modifies_1_from_to b from to h1 h2 /\ ubuffer_disjoint #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) b'))
(ensures (ubuffer_preserved #(frameOf b) #(as_addr b) b' h1 h2))
= ()
val modifies_1_null (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
: Lemma (requires (modifies_1 b h1 h2 /\ g_is_null b))
(ensures (modifies_0 h1 h2))
let modifies_1_null #_ #_ #_ _ _ _ = ()
let modifies_addr_of_preserves_not_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem)
:GTot Type0
= forall (r: HS.rid) (n: nat) .
((r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)) ==>
(n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r))
let modifies_addr_of' (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0 =
modifies_0_preserves_regions h1 h2 /\
modifies_1_preserves_mreferences b h1 h2 /\
modifies_addr_of_preserves_not_unused_in b h1 h2
val modifies_addr_of (#a:Type0) (#rrel:srel a) (#rel:srel a) (b:mbuffer a rrel rel) (h1 h2:HS.mem) :GTot Type0
let modifies_addr_of = modifies_addr_of'
val modifies_addr_of_live_region (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid)
:Lemma (requires (modifies_addr_of b h1 h2 /\ HS.live_region h1 r))
(ensures (HS.live_region h2 r))
let modifies_addr_of_live_region #_ #_ #_ _ _ _ _ = ()
val modifies_addr_of_mreference (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
(#a':Type0) (#pre:Preorder.preorder a') (r':HS.mreference a' pre)
: Lemma (requires (modifies_addr_of b h1 h2 /\ (frameOf b <> HS.frameOf r' \/ as_addr b <> HS.as_addr r') /\ h1 `HS.contains` r'))
(ensures (h2 `HS.contains` r' /\ h1 `HS.sel` r' == h2 `HS.sel` r'))
let modifies_addr_of_mreference #_ #_ #_ _ _ _ #_ #_ _ = ()
val modifies_addr_of_unused_in (#a:Type0) (#rrel:srel a) (#rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem) (r:HS.rid) (n:nat)
: Lemma (requires (modifies_addr_of b h1 h2 /\
(r <> frameOf b \/ n <> as_addr b) /\
HS.live_region h1 r /\ HS.live_region h2 r /\
n `Heap.addr_unused_in` (HS.get_hmap h2 `Map.sel` r)))
(ensures (n `Heap.addr_unused_in` (HS.get_hmap h1 `Map.sel` r)))
let modifies_addr_of_unused_in #_ #_ #_ _ _ _ _ _ = ()
module MG = FStar.ModifiesGen
let cls : MG.cls ubuffer = MG.Cls #ubuffer
ubuffer_includes
(fun #r #a x -> ubuffer_includes_refl x)
(fun #r #a x1 x2 x3 -> ubuffer_includes_trans x1 x2 x3)
ubuffer_disjoint
(fun #r #a x1 x2 -> ubuffer_disjoint_sym x1 x2)
(fun #r #a larger1 larger2 smaller1 smaller2 -> ubuffer_disjoint_includes larger1 larger2 smaller1 smaller2)
ubuffer_preserved
(fun #r #a x h -> ubuffer_preserved_refl x h)
(fun #r #a x h1 h2 h3 -> ubuffer_preserved_trans x h1 h2 h3)
(fun #r #a b h1 h2 f -> same_mreference_ubuffer_preserved b h1 h2 f)
let loc = MG.loc cls
let _ = intro_ambient loc
let loc_none = MG.loc_none
let _ = intro_ambient loc_none
let loc_union = MG.loc_union
let _ = intro_ambient loc_union
let loc_union_idem = MG.loc_union_idem
let loc_union_comm = MG.loc_union_comm
let loc_union_assoc = MG.loc_union_assoc
let loc_union_loc_none_l = MG.loc_union_loc_none_l
let loc_union_loc_none_r = MG.loc_union_loc_none_r
let loc_buffer_from_to #a #rrel #rel b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then MG.loc_none
else
MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to)
let loc_buffer #_ #_ #_ b =
if g_is_null b then MG.loc_none
else MG.loc_of_aloc #_ #_ #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_buffer_eq #_ #_ #_ _ = ()
let loc_buffer_from_to_high #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_none #_ #_ #_ _ _ _ = ()
let loc_buffer_from_to_mgsub #_ #_ #_ _ _ _ _ _ _ = ()
let loc_buffer_mgsub_eq #_ #_ #_ _ _ _ _ = ()
let loc_buffer_null _ _ _ = ()
let loc_buffer_from_to_eq #_ #_ #_ _ _ _ = ()
let loc_buffer_mgsub_rel_eq #_ #_ #_ _ _ _ _ _ = ()
let loc_addresses = MG.loc_addresses
let loc_regions = MG.loc_regions
let loc_includes = MG.loc_includes
let loc_includes_refl = MG.loc_includes_refl
let loc_includes_trans = MG.loc_includes_trans
let loc_includes_union_r = MG.loc_includes_union_r
let loc_includes_union_l = MG.loc_includes_union_l
let loc_includes_none = MG.loc_includes_none
val loc_includes_buffer (#a:Type0) (#rrel1:srel a) (#rrel2:srel a) (#rel1:srel a) (#rel2:srel a)
(b1:mbuffer a rrel1 rel1) (b2:mbuffer a rrel2 rel2)
:Lemma (requires (frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2 /\
ubuffer_includes0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_includes (loc_buffer b1) (loc_buffer b2)))
let loc_includes_buffer #t #_ #_ #_ #_ b1 b2 =
let t1 = ubuffer (frameOf b1) (as_addr b1) in
MG.loc_includes_aloc #_ #cls #(frameOf b1) #(as_addr b1) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_includes_gsub_buffer_r l #_ #_ #_ b i len sub_rel =
let b' = mgsub sub_rel b i len in
loc_includes_buffer b b';
loc_includes_trans l (loc_buffer b) (loc_buffer b')
let loc_includes_gsub_buffer_l #_ #_ #rel b i1 len1 sub_rel1 i2 len2 sub_rel2 =
let b1 = mgsub sub_rel1 b i1 len1 in
let b2 = mgsub sub_rel2 b i2 len2 in
loc_includes_buffer b1 b2
let loc_includes_loc_buffer_loc_buffer_from_to #_ #_ #_ b from to =
if ubuffer_of_buffer_from_to_none_cond b from to
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) (ubuffer_of_buffer_from_to b from to)
let loc_includes_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_includes_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
#push-options "--z3rlimit 20"
let loc_includes_as_seq #_ #rrel #_ #_ h1 h2 larger smaller =
if Null? smaller then () else
if Null? larger then begin
MG.loc_includes_none_elim (loc_buffer smaller);
MG.loc_of_aloc_not_none #_ #cls #(frameOf smaller) #(as_addr smaller) (ubuffer_of_buffer smaller)
end else begin
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller);
let ul = Ghost.reveal (ubuffer_of_buffer larger) in
let us = Ghost.reveal (ubuffer_of_buffer smaller) in
assert (as_seq h1 smaller == Seq.slice (as_seq h1 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller));
assert (as_seq h2 smaller == Seq.slice (as_seq h2 larger) (us.b_offset - ul.b_offset) (us.b_offset - ul.b_offset + length smaller))
end
#pop-options
let loc_includes_addresses_buffer #a #rrel #srel preserve_liveness r s p =
MG.loc_includes_addresses_aloc #_ #cls preserve_liveness r s #(as_addr p) (ubuffer_of_buffer p)
let loc_includes_region_buffer #_ #_ #_ preserve_liveness s b =
MG.loc_includes_region_aloc #_ #cls preserve_liveness s #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let loc_includes_region_addresses = MG.loc_includes_region_addresses #_ #cls
let loc_includes_region_region = MG.loc_includes_region_region #_ #cls
let loc_includes_region_union_l = MG.loc_includes_region_union_l
let loc_includes_addresses_addresses = MG.loc_includes_addresses_addresses cls
let loc_disjoint = MG.loc_disjoint
let loc_disjoint_sym = MG.loc_disjoint_sym
let loc_disjoint_none_r = MG.loc_disjoint_none_r
let loc_disjoint_union_r = MG.loc_disjoint_union_r
let loc_disjoint_includes = MG.loc_disjoint_includes
val loc_disjoint_buffer (#a1 #a2:Type0) (#rrel1 #rel1:srel a1) (#rrel2 #rel2:srel a2)
(b1:mbuffer a1 rrel1 rel1) (b2:mbuffer a2 rrel2 rel2)
:Lemma (requires ((frameOf b1 == frameOf b2 /\ as_addr b1 == as_addr b2) ==>
ubuffer_disjoint0 #(frameOf b1) #(frameOf b2) #(as_addr b1) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)))
(ensures (loc_disjoint (loc_buffer b1) (loc_buffer b2)))
let loc_disjoint_buffer #_ #_ #_ #_ #_ #_ b1 b2 =
MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
let loc_disjoint_gsub_buffer #_ #_ #_ b i1 len1 sub_rel1 i2 len2 sub_rel2 =
loc_disjoint_buffer (mgsub sub_rel1 b i1 len1) (mgsub sub_rel2 b i2 len2)
let loc_disjoint_loc_buffer_from_to #_ #_ #_ b from1 to1 from2 to2 =
if ubuffer_of_buffer_from_to_none_cond b from1 to1 || ubuffer_of_buffer_from_to_none_cond b from2 to2
then ()
else MG.loc_disjoint_aloc_intro #_ #cls #(frameOf b) #(as_addr b) #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from1 to1) (ubuffer_of_buffer_from_to b from2 to2)
let loc_disjoint_addresses = MG.loc_disjoint_addresses_intro #_ #cls
let loc_disjoint_regions = MG.loc_disjoint_regions #_ #cls
let modifies = MG.modifies
let modifies_live_region = MG.modifies_live_region
let modifies_mreference_elim = MG.modifies_mreference_elim
let modifies_buffer_elim #_ #_ #_ b p h h' =
if g_is_null b
then
assert (as_seq h b `Seq.equal` as_seq h' b)
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) p h h' ;
ubuffer_preserved_elim b h h'
end
let modifies_buffer_from_to_elim #_ #_ #_ b from to p h h' =
if g_is_null b
then ()
else begin
MG.modifies_aloc_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) p h h' ;
ubuffer_preserved_from_to_elim b from to h h'
end
let modifies_refl = MG.modifies_refl
let modifies_loc_includes = MG.modifies_loc_includes
let address_liveness_insensitive_locs = MG.address_liveness_insensitive_locs _
let region_liveness_insensitive_locs = MG.region_liveness_insensitive_locs _
let address_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_address_liveness_insensitive_locs_aloc #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let address_liveness_insensitive_addresses =
MG.loc_includes_address_liveness_insensitive_locs_addresses cls
let region_liveness_insensitive_buffer #_ #_ #_ b =
MG.loc_includes_region_liveness_insensitive_locs_loc_of_aloc #_ cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b)
let region_liveness_insensitive_addresses =
MG.loc_includes_region_liveness_insensitive_locs_loc_addresses cls
let region_liveness_insensitive_regions =
MG.loc_includes_region_liveness_insensitive_locs_loc_regions cls
let region_liveness_insensitive_address_liveness_insensitive =
MG.loc_includes_region_liveness_insensitive_locs_address_liveness_insensitive_locs cls
let modifies_liveness_insensitive_mreference = MG.modifies_preserves_liveness
let modifies_liveness_insensitive_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else
liveness_preservation_intro h h' x (fun t' pre r ->
MG.modifies_preserves_liveness_strong l1 l2 h h' r (ubuffer_of_buffer x))
let modifies_liveness_insensitive_region = MG.modifies_preserves_region_liveness
let modifies_liveness_insensitive_region_mreference = MG.modifies_preserves_region_liveness_reference
let modifies_liveness_insensitive_region_buffer l1 l2 h h' #_ #_ #_ x =
if g_is_null x then ()
else MG.modifies_preserves_region_liveness_aloc l1 l2 h h' #(frameOf x) #(as_addr x) (ubuffer_of_buffer x)
let modifies_trans = MG.modifies_trans
let modifies_only_live_regions = MG.modifies_only_live_regions
let no_upd_fresh_region = MG.no_upd_fresh_region
let new_region_modifies = MG.new_region_modifies #_ cls
let modifies_fresh_frame_popped = MG.modifies_fresh_frame_popped
let modifies_loc_regions_intro = MG.modifies_loc_regions_intro #_ #cls
let modifies_loc_addresses_intro = MG.modifies_loc_addresses_intro #_ #cls
let modifies_ralloc_post = MG.modifies_ralloc_post #_ #cls
let modifies_salloc_post = MG.modifies_salloc_post #_ #cls
let modifies_free = MG.modifies_free #_ #cls
let modifies_none_modifies = MG.modifies_none_modifies #_ #cls
let modifies_upd = MG.modifies_upd #_ #cls
val modifies_0_modifies
(h1 h2: HS.mem)
: Lemma
(requires (modifies_0 h1 h2))
(ensures (modifies loc_none h1 h2))
let modifies_0_modifies h1 h2 =
MG.modifies_none_intro #_ #cls h1 h2
(fun r -> modifies_0_live_region h1 h2 r)
(fun t pre b -> modifies_0_mreference #t #pre h1 h2 b)
(fun r n -> modifies_0_unused_in h1 h2 r n)
val modifies_1_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_1 b h1 h2))
(ensures (modifies (loc_buffer b) h1 h2))
let modifies_1_modifies #t #_ #_ b h1 h2 =
if g_is_null b
then begin
modifies_1_null b h1 h2;
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer b) h1 h2
(fun r -> modifies_1_live_region b h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer b);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer b) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_mreference b h1 h2 p
)
(fun t pre p ->
modifies_1_liveness b h1 h2 p
)
(fun r n ->
modifies_1_unused_in b h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer b);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer b) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_ubuffer #t b h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_mreference b h1 h2 r_)
)
val modifies_1_from_to_modifies
(#a:Type0)(#rrel #rel:srel a)
(b:mbuffer a rrel rel) (from to: U32.t) (h1 h2:HS.mem)
:Lemma (requires (modifies_1_from_to b from to h1 h2))
(ensures (modifies (loc_buffer_from_to b from to) h1 h2))
let modifies_1_from_to_modifies #t #_ #_ b from to h1 h2 =
if ubuffer_of_buffer_from_to_none_cond b from to
then begin
modifies_0_modifies h1 h2
end else
MG.modifies_intro (loc_buffer_from_to b from to) h1 h2
(fun r -> modifies_1_from_to_live_region b from to h1 h2 r)
(fun t pre p ->
loc_disjoint_sym (loc_mreference p) (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_addresses_elim #_ #cls #(frameOf b) #(as_addr b) (ubuffer_of_buffer_from_to b from to) true (HS.frameOf p) (Set.singleton (HS.as_addr p));
modifies_1_from_to_mreference b from to h1 h2 p
)
(fun t pre p ->
modifies_1_from_to_liveness b from to h1 h2 p
)
(fun r n ->
modifies_1_from_to_unused_in b from to h1 h2 r n
)
(fun r' a' b' ->
loc_disjoint_sym (MG.loc_of_aloc b') (loc_buffer_from_to b from to);
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b) #(as_addr b) #r' #a' (ubuffer_of_buffer_from_to b from to) b';
if frameOf b = r' && as_addr b = a'
then
modifies_1_from_to_ubuffer #t b from to h1 h2 b'
else
same_mreference_ubuffer_preserved #r' #a' b' h1 h2
(fun a_ pre_ r_ -> modifies_1_from_to_mreference b from to h1 h2 r_)
)
val modifies_addr_of_modifies
(#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (h1 h2:HS.mem)
:Lemma (requires (modifies_addr_of b h1 h2))
(ensures (modifies (loc_addr_of_buffer b) h1 h2))
let modifies_addr_of_modifies #t #_ #_ b h1 h2 =
MG.modifies_address_intro #_ #cls (frameOf b) (as_addr b) h1 h2
(fun r -> modifies_addr_of_live_region b h1 h2 r)
(fun t pre p ->
modifies_addr_of_mreference b h1 h2 p
)
(fun r n ->
modifies_addr_of_unused_in b h1 h2 r n
)
val modifies_loc_buffer_from_to_intro'
(#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel)
(from to: U32.t)
(l: loc) (h h' : HS.mem)
: Lemma
(requires (
let s = as_seq h b in
let s' = as_seq h' b in
not (g_is_null b) /\
live h b /\
modifies (loc_union l (loc_buffer b)) h h' /\
U32.v from <= U32.v to /\
U32.v to <= length b /\
Seq.slice s 0 (U32.v from) `Seq.equal` Seq.slice s' 0 (U32.v from) /\
Seq.slice s (U32.v to) (length b) `Seq.equal` Seq.slice s' (U32.v to) (length b)
))
(ensures (modifies (loc_union l (loc_buffer_from_to b from to)) h h'))
#push-options "--z3rlimit 16"
let modifies_loc_buffer_from_to_intro' #a #rrel #rel b from to l h h' =
let r0 = frameOf b in
let a0 = as_addr b in
let bb : ubuffer r0 a0 = ubuffer_of_buffer b in
modifies_loc_includes (loc_union l (loc_addresses true r0 (Set.singleton a0))) h h' (loc_union l (loc_buffer b));
MG.modifies_strengthen l #r0 #a0 (ubuffer_of_buffer_from_to b from to) h h' (fun f (x: ubuffer r0 a0) ->
ubuffer_preserved_intro x h h'
(fun t' rrel' rel' b' -> f _ _ (Buffer?.content b'))
(fun t' rrel' rel' b' ->
// prove that the types, rrels, rels are equal
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
assert (Seq.seq t' == Seq.seq a);
let _s0 : Seq.seq a = as_seq h b in
let _s1 : Seq.seq t' = coerce_eq _ _s0 in
lemma_equal_instances_implies_equal_types a t' _s0 _s1;
let boff = U32.v (Buffer?.idx b) in
let from_ = boff + U32.v from in
let to_ = boff + U32.v to in
let ({ b_max_length = ml; b_offset = xoff; b_length = xlen; b_is_mm = is_mm }) = Ghost.reveal x in
let ({ b_max_length = _; b_offset = b'off; b_length = b'len }) = Ghost.reveal (ubuffer_of_buffer b') in
let bh = as_seq h b in
let bh' = as_seq h' b in
let xh = Seq.slice (as_seq h b') (xoff - b'off) (xoff - b'off + xlen) in
let xh' = Seq.slice (as_seq h' b') (xoff - b'off) (xoff - b'off + xlen) in
let prf (i: nat) : Lemma
(requires (i < xlen))
(ensures (i < xlen /\ Seq.index xh i == Seq.index xh' i))
= let xi = xoff + i in
let bi : ubuffer r0 a0 =
Ghost.hide ({ b_max_length = ml; b_offset = xi; b_length = 1; b_is_mm = is_mm; })
in
assert (Seq.index xh i == Seq.index (Seq.slice (as_seq h b') (xi - b'off) (xi - b'off + 1)) 0);
assert (Seq.index xh' i == Seq.index (Seq.slice (as_seq h' b') (xi - b'off) (xi - b'off + 1)) 0);
let li = MG.loc_of_aloc bi in
MG.loc_includes_aloc #_ #cls x bi;
loc_disjoint_includes l (MG.loc_of_aloc x) l li;
if xi < boff || boff + length b <= xi
then begin
MG.loc_disjoint_aloc_intro #_ #cls bb bi;
assert (loc_disjoint (loc_union l (loc_buffer b)) li);
MG.modifies_aloc_elim bi (loc_union l (loc_buffer b)) h h'
end else
if xi < from_
then begin
assert (Seq.index xh i == Seq.index (Seq.slice bh 0 (U32.v from)) (xi - boff));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' 0 (U32.v from)) (xi - boff))
end else begin
assert (to_ <= xi);
assert (Seq.index xh i == Seq.index (Seq.slice bh (U32.v to) (length b)) (xi - to_));
assert (Seq.index xh' i == Seq.index (Seq.slice bh' (U32.v to) (length b)) (xi - to_))
end
in
Classical.forall_intro (Classical.move_requires prf);
assert (xh `Seq.equal` xh')
)
)
#pop-options
let modifies_loc_buffer_from_to_intro #a #rrel #rel b from to l h h' =
if g_is_null b
then ()
else modifies_loc_buffer_from_to_intro' b from to l h h'
let does_not_contain_addr = MG.does_not_contain_addr
let not_live_region_does_not_contain_addr = MG.not_live_region_does_not_contain_addr
let unused_in_does_not_contain_addr = MG.unused_in_does_not_contain_addr
let addr_unused_in_does_not_contain_addr = MG.addr_unused_in_does_not_contain_addr
let free_does_not_contain_addr = MG.free_does_not_contain_addr
let does_not_contain_addr_elim = MG.does_not_contain_addr_elim
let modifies_only_live_addresses = MG.modifies_only_live_addresses
let loc_not_unused_in = MG.loc_not_unused_in _
let loc_unused_in = MG.loc_unused_in _
let loc_regions_unused_in = MG.loc_regions_unused_in cls
let loc_unused_in_not_unused_in_disjoint =
MG.loc_unused_in_not_unused_in_disjoint cls
let not_live_region_loc_not_unused_in_disjoint = MG.not_live_region_loc_not_unused_in_disjoint cls
let live_loc_not_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.does_not_contain_addr_addr_unused_in h) (frameOf b, as_addr b);
MG.loc_addresses_not_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let unused_in_loc_unused_in #_ #_ #_ b h =
unused_in_equiv b h;
Classical.move_requires (MG.addr_unused_in_does_not_contain_addr h) (frameOf b, as_addr b);
MG.loc_addresses_unused_in cls (frameOf b) (Set.singleton (as_addr b)) h;
()
let modifies_address_liveness_insensitive_unused_in =
MG.modifies_address_liveness_insensitive_unused_in cls
let modifies_only_not_unused_in = MG.modifies_only_not_unused_in
let mreference_live_loc_not_unused_in =
MG.mreference_live_loc_not_unused_in cls
let mreference_unused_in_loc_unused_in =
MG.mreference_unused_in_loc_unused_in cls
let modifies_loc_unused_in l h1 h2 l' =
modifies_loc_includes address_liveness_insensitive_locs h1 h2 l;
modifies_address_liveness_insensitive_unused_in h1 h2;
loc_includes_trans (loc_unused_in h1) (loc_unused_in h2) l'
let fresh_frame_modifies h0 h1 = MG.fresh_frame_modifies #_ cls h0 h1
let popped_modifies = MG.popped_modifies #_ cls
let modifies_remove_new_locs l_fresh l_aux l_goal h1 h2 h3 =
modifies_only_not_unused_in l_goal h1 h3
let disjoint_neq #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
let empty_disjoint
#t1 #t2 #rrel1 #rel1 #rrel2 #rel2 b1 b2
= let r = frameOf b1 in
let a = as_addr b1 in
if r = frameOf b2 && a = as_addr b2 then
MG.loc_disjoint_aloc_intro #_ #cls #r #a #r #a (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
else ()
(*
let includes_live #a #rrel #rel1 #rel2 h larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let includes_frameOf_as_addr #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
let pointer_distinct_sel_disjoint #a #_ #_ #_ #_ b1 b2 h =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2
then begin
HS.mreference_distinct_sel_disjoint h (Buffer?.content b1) (Buffer?.content b2);
loc_disjoint_buffer b1 b2
end
else
loc_disjoint_buffer b1 b2
let is_null #_ #_ #_ b = Null? b
let msub #a #rrel #rel sub_rel b i len =
match b with
| Null -> Null
| Buffer max_len content i0 len0 ->
Buffer max_len content (U32.add i0 i) len
let moffset #a #rrel #rel sub_rel b i =
match b with
| Null -> Null
| Buffer max_len content i0 len ->
Buffer max_len content (U32.add i0 i) (Ghost.hide ((U32.sub (Ghost.reveal len) i)))
let index #_ #_ #_ b i =
let open HST in
let s = ! (Buffer?.content b) in
Seq.index s (U32.v (Buffer?.idx b) + U32.v i)
let g_upd_seq #_ #_ #_ b s h =
if Seq.length s = 0 then h
else
let s0 = HS.sel h (Buffer?.content b) in
let Buffer _ content idx length = b in
HS.upd h (Buffer?.content b) (Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v length) s)
let lemma_g_upd_with_same_seq #_ #_ #_ b h =
if Null? b then ()
else
let open FStar.UInt32 in
let Buffer _ content idx length = b in
let s = HS.sel h content in
assert (Seq.equal (Seq.replace_subseq s (v idx) (v idx + v length) (Seq.slice s (v idx) (v idx + v length))) s);
HS.lemma_heap_equality_upd_with_sel h (Buffer?.content b)
#push-options "--z3rlimit 48"
let g_upd_seq_as_seq #a #_ #_ b s h =
let h' = g_upd_seq b s h in
if g_is_null b then assert (Seq.equal s Seq.empty)
else begin
assert (Seq.equal (as_seq h' b) s);
// prove modifies_1_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_modifies b h h'
end
let g_upd_modifies_strong #_ #_ #_ b i v h =
let h' = g_upd b i v h in
// prove modifies_1_from_to_preserves_ubuffers
Heap.lemma_distinct_addrs_distinct_preorders ();
Heap.lemma_distinct_addrs_distinct_mm ();
s_lemma_equal_instances_implies_equal_types ();
modifies_1_from_to_modifies b (U32.uint_to_t i) (U32.uint_to_t (i + 1)) h h'
#pop-options
let upd' #_ #_ #_ b i v =
let open HST in
let h = get() in
let Buffer max_length content idx len = b in
let s0 = !content in
let sb0 = Seq.slice s0 (U32.v idx) (U32.v max_length) in
let s_upd = Seq.upd sb0 (U32.v i) v in
let sf = Seq.replace_subseq s0 (U32.v idx) (U32.v max_length) s_upd in
assert (sf `Seq.equal`
Seq.replace_subseq s0 (U32.v idx) (U32.v idx + U32.v len) (Seq.upd (as_seq h b) (U32.v i) v));
content := sf
let recallable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) :GTot Type0 =
(not (g_is_null b)) ==> (
HST.is_eternal_region (frameOf b) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_buf #_ #_ #_ b =
(not (g_is_null b)) ==> (
HS.is_heap_color (HS.color (frameOf b)) /\
not (HS.is_mm (Buffer?.content b)) /\
buffer_compatible b
)
let region_lifetime_sub #a #rrel #rel #subrel b0 b1 =
match b1 with
| Null -> ()
| Buffer max_len content idx length ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j subrel)
let recallable_null #_ #_ #_ = ()
let recallable_mgsub #_ #rrel #rel b i len sub_rel =
match b with
| Null -> ()
| Buffer max_len content idx length ->
lemma_seq_sub_compatibility_is_transitive (U32.v max_len) rrel
(U32.v idx) (U32.v idx + U32.v length) rel
(U32.v i) (U32.v i + U32.v len) sub_rel
(*
let recallable_includes #_ #_ #_ #_ #_ #_ larger smaller =
if Null? larger || Null? smaller then ()
else
MG.loc_includes_aloc_elim #_ #cls #(frameOf larger) #(frameOf smaller) #(as_addr larger) #(as_addr smaller) (ubuffer_of_buffer larger) (ubuffer_of_buffer smaller)
*)
let recall #_ #_ #_ b = if Null? b then () else HST.recall (Buffer?.content b)
private let spred_as_mempred (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (p:spred a)
:HST.mem_predicate
= fun h ->
buffer_compatible b ==>
p (as_seq h b)
let witnessed #_ #rrel #rel b p =
match b with
| Null -> p Seq.empty
| Buffer max_length content idx length ->
HST.token_p content (spred_as_mempred b p)
private let lemma_stable_on_rel_is_stable_on_rrel (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (p:spred a)
:Lemma (requires (Buffer? b /\ stable_on p rel))
(ensures (HST.stable_on (spred_as_mempred b p) (Buffer?.content b)))
= let Buffer max_length content idx length = b in
let mp = spred_as_mempred b p in
let aux (h0 h1:HS.mem) :Lemma ((mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content)) ==> mp h1)
= Classical.arrow_to_impl #(mp h0 /\ rrel (HS.sel h0 content) (HS.sel h1 content) /\ buffer_compatible b) #(mp h1)
(fun _ -> assert (rel (as_seq h0 b) (as_seq h1 b)))
in
Classical.forall_intro_2 aux
let witness_p #a #rrel #rel b p =
match b with
| Null -> ()
| Buffer _ content _ _ ->
lemma_stable_on_rel_is_stable_on_rrel b p;
//AR: TODO: the proof doesn't go through without this assertion, which should follow directly from the lemma call
assert (HST.stable_on #(Seq.lseq a (U32.v (Buffer?.max_length b))) #(srel_to_lsrel (U32.v (Buffer?.max_length b)) rrel) (spred_as_mempred b p) (Buffer?.content b));
HST.witness_p content (spred_as_mempred b p)
let recall_p #_ #_ #_ b p =
match b with
| Null -> ()
| Buffer _ content _ _ -> HST.recall_p content (spred_as_mempred b p)
let witnessed_functorial #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> assert (as_seq HS.empty_mem b1 == Seq.empty)
| Buffer _ content _ _, _ ->
assert (forall (len:nat) (i:nat) (j:nat{i <= j /\ j <= len}). compatible_sub_preorder len rrel i j rel1);
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let witnessed_functorial_st #a #rrel #rel1 #rel2 b1 b2 i len s1 s2 =
match b1, b2 with
| Null, Null -> ()
| Buffer _ content _ _, _ ->
HST.token_functoriality content (spred_as_mempred b1 s1) (spred_as_mempred b2 s2)
let freeable (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) =
(not (g_is_null b)) /\
HS.is_mm (Buffer?.content b) /\
HS.is_heap_color (HS.color (frameOf b)) /\
U32.v (Buffer?.max_length b) > 0 /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b
let free #_ #_ #_ b = HST.rfree (Buffer?.content b)
let freeable_length #_ #_ #_ b = ()
let freeable_disjoint #_ #_ #_ #_ #_ #_ b1 b2 =
if frameOf b1 = frameOf b2 && as_addr b1 = as_addr b2 then
MG.loc_disjoint_aloc_elim #_ #cls #(frameOf b1) #(as_addr b1) #(frameOf b2) #(as_addr b2) (ubuffer_of_buffer b1) (ubuffer_of_buffer b2)
private let alloc_heap_common (#a:Type0) (#rrel:srel a)
(r:HST.erid) (len:U32.t{U32.v len > 0}) (s:Seq.seq a{Seq.length s == U32.v len})
(mm:bool)
:HST.ST (lmbuffer a rrel rrel (U32.v len))
(requires (fun _ -> True))
(ensures (fun h0 b h1 -> alloc_post_mem_common b h0 h1 s /\
frameOf b == r /\
HS.is_mm (Buffer?.content b) == mm /\
Buffer?.idx b == 0ul /\
Ghost.reveal (Buffer?.length b) == Buffer?.max_length b))
= lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
if mm then HST.ralloc_mm r s else HST.ralloc r s
in
let b = Buffer len content 0ul (Ghost.hide len) in
b
let mgcmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) false
private let read_sub_buffer (#a:Type0) (#rrel #rel:srel a)
(b:mbuffer a rrel rel) (idx len:U32.t)
: HST.ST (Seq.seq a)
(requires fun h0 ->
live h0 b /\ U32.v len > 0 /\
U32.v idx + U32.v len <= length b)
(ensures fun h0 s h1 ->
h0 == h1 /\
s == Seq.slice (as_seq h0 b) (U32.v idx) (U32.v idx + U32.v len))
= let open HST in
let s = ! (Buffer?.content b) in //the whole allocation unit
let s = Seq.slice s (U32.v (Buffer?.idx b))
(U32.v (Buffer?.max_length b)) in //b buffer
Seq.slice s (U32.v idx) (U32.v idx + U32.v len) //slice of b
let mgcmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) false
let mmalloc #_ #_ r init len =
alloc_heap_common r len (Seq.create (U32.v len) init) true
let mmalloc_and_blit #_ #_ r #_ #_ src id_src len =
alloc_heap_common r len (read_sub_buffer src id_src len) true
let malloca #a #rrel init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (Seq.create (U32.v len) init)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_and_blit #a #rrel #_ #_ src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc (read_sub_buffer src id_src len)
in
Buffer len content 0ul (Ghost.hide len)
let malloca_of_list #a #rrel init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.salloc s
in
Buffer len content 0ul (Ghost.hide len)
let mgcmalloc_of_list #a #rrel r init =
let len = U32.uint_to_t (FStar.List.Tot.length init) in
let s = Seq.seq_of_list init in
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc r s
in
Buffer len content 0ul (Ghost.hide len)
let mmalloc_drgn #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_mm #a #rrel d init len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content : HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn_mm d (Seq.create (U32.v len) init)
in
Buffer len content 0ul len
let mmalloc_drgn_and_blit #a #rrel #_ #_ d src id_src len =
lemma_seq_sub_compatilibity_is_reflexive (U32.v len) rrel;
let content: HST.mreference (Seq.lseq a (U32.v len)) (srel_to_lsrel (U32.v len) rrel) =
HST.ralloc_drgn d (read_sub_buffer src id_src len)
in
Buffer len content 0ul len
#push-options "--max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --z3rlimit 64"
let blit #a #rrel1 #rrel2 #rel1 #rel2 src idx_src dst idx_dst len =
let open HST in
match src, dst with
| Buffer _ _ _ _, Buffer _ _ _ _ ->
if len = 0ul then ()
else
let h = get () in
let Buffer max_length1 content1 idx1 length1 = src in
let Buffer max_length2 content2 idx2 length2 = dst in
let s_full1 = !content1 in
let s_full2 = !content2 in
let s1 = Seq.slice s_full1 (U32.v idx1) (U32.v max_length1) in
let s2 = Seq.slice s_full2 (U32.v idx2) (U32.v max_length2) in
let s_sub_src = Seq.slice s1 (U32.v idx_src) (U32.v idx_src + U32.v len) in
let s2' = Seq.replace_subseq s2 (U32.v idx_dst) (U32.v idx_dst + U32.v len) s_sub_src in
let s_full2' = Seq.replace_subseq s_full2 (U32.v idx2) (U32.v max_length2) s2' in
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst) (U32.v idx_dst + U32.v len)) s_sub_src);
assert (Seq.equal (Seq.slice s2' 0 (U32.v idx_dst)) (Seq.slice s2 0 (U32.v idx_dst)));
assert (Seq.equal (Seq.slice s2' (U32.v idx_dst + U32.v len) (length dst))
(Seq.slice s2 (U32.v idx_dst + U32.v len) (length dst)));
// AF: Needed to trigger the preorder relation. A bit verbose because the second sequence
// has a ghost computation (U32.v (Ghost.reveal length))
assert (s_full2' `Seq.equal`
Seq.replace_subseq s_full2
(U32.v idx2)
(U32.v idx2 + U32.v length2)
(Seq.replace_subseq (as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (as_seq h src)
(U32.v idx_src)
(U32.v idx_src + U32.v len)
)
)
);
content2 := s_full2';
let h1 = get () in
assert (s_full2' `Seq.equal` Seq.replace_subseq s_full2 (U32.v idx2) (U32.v idx2 + U32.v length2) (Seq.slice s2' 0 (U32.v length2)));
assert (h1 == g_upd_seq dst (Seq.slice s2' 0 (U32.v length2)) h);
g_upd_seq_as_seq dst (Seq.slice s2' 0 (U32.v length2)) h //for modifies clause
| _, _ -> ()
#push-options "--z3rlimit 128 --max_fuel 0 --max_ifuel 1 --initial_ifuel 1 --z3cliopt smt.qi.EAGER_THRESHOLD=4"
let fill' (#t:Type) (#rrel #rel: srel t)
(b: mbuffer t rrel rel)
(z:t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
live h b /\
U32.v len <= length b /\
rel (as_seq h b) (Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))
))
(ensures (fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\
live h1 b /\
Seq.slice (as_seq h1 b) 0 (U32.v len) `Seq.equal` Seq.create (U32.v len) z /\
Seq.slice (as_seq h1 b) (U32.v len) (length b) `Seq.equal` Seq.slice (as_seq h0 b) (U32.v len) (length b) | false | false | LowStar.Monotonic.Buffer.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.EAGER_THRESHOLD=4"
],
"z3refresh": false,
"z3rlimit": 128,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fill' (#t: Type) (#rrel #rel: srel t) (b: mbuffer t rrel rel) (z: t) (len: U32.t)
: HST.Stack unit
(requires
(fun h ->
live h b /\ U32.v len <= length b /\
rel (as_seq h b)
(Seq.replace_subseq (as_seq h b) 0 (U32.v len) (Seq.create (U32.v len) z))))
(ensures
(fun h0 _ h1 ->
modifies (loc_buffer b) h0 h1 /\ live h1 b /\
(Seq.slice (as_seq h1 b) 0 (U32.v len)) `Seq.equal` (Seq.create (U32.v len) z) /\
(Seq.slice (as_seq h1 b) (U32.v len) (length b))
`Seq.equal`
(Seq.slice (as_seq h0 b) (U32.v len) (length b)))) | [] | LowStar.Monotonic.Buffer.fill' | {
"file_name": "ulib/LowStar.Monotonic.Buffer.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: LowStar.Monotonic.Buffer.mbuffer t rrel rel -> z: t -> len: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 5,
"end_line": 1645,
"start_col": 2,
"start_line": 1627
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tu = twice () | let tu = | false | null | false | twice () | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.twice",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p} | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tu : FStar.Relational.Relational.rel Prims.unit Prims.unit | [] | FStar.Relational.Relational.tu | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | FStar.Relational.Relational.rel Prims.unit Prims.unit | {
"end_col": 17,
"end_line": 28,
"start_col": 9,
"start_line": 28
} |
|
Prims.Tot | val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = | false | null | false | R (f x1 y1) (f x2 y2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.double",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Relational.Relational.rel",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c) | [] | FStar.Relational.Relational.rel_map2T | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: 'a -> _: 'b -> 'c) ->
_: FStar.Relational.Relational.double 'a ->
_: FStar.Relational.Relational.double 'b
-> FStar.Relational.Relational.double 'c | {
"end_col": 59,
"end_line": 38,
"start_col": 38,
"start_line": 38
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Minus = rel_map2T (fun x y -> x - y) | let op_Hat_Minus = | false | null | false | rel_map2T (fun x y -> x - y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.int",
"Prims.op_Subtraction"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Minus : _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | [] | FStar.Relational.Relational.op_Hat_Minus | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | {
"end_col": 47,
"end_line": 51,
"start_col": 19,
"start_line": 51
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let twice x = R x x | let twice x = | false | null | false | R x x | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.R",
"FStar.Relational.Relational.rel"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p} | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val twice : x: _ -> FStar.Relational.Relational.rel _ _ | [] | FStar.Relational.Relational.twice | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: _ -> FStar.Relational.Relational.rel _ _ | {
"end_col": 19,
"end_line": 27,
"start_col": 14,
"start_line": 27
} |
|
Prims.Tot | val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = | false | null | false | R (f x1 y1) (f x2 y2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"Prims.eqtype",
"FStar.Relational.Relational.double",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Relational.Relational.rel",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c) | [] | FStar.Relational.Relational.rel_map2Teq | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: a -> _: b -> c) ->
_: FStar.Relational.Relational.double a ->
_: FStar.Relational.Relational.double b
-> FStar.Relational.Relational.double c | {
"end_col": 70,
"end_line": 35,
"start_col": 49,
"start_line": 35
} |
Prims.GTot | val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = | false | null | false | R (f x1 y1) (f x2 y2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"sometrivial"
] | [
"FStar.Relational.Relational.double",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Relational.Relational.rel",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c) | [] | FStar.Relational.Relational.rel_map2G | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: 'a -> _: 'b -> Prims.GTot 'c) ->
_: FStar.Relational.Relational.double 'a ->
_: FStar.Relational.Relational.double 'b
-> Prims.GTot (FStar.Relational.Relational.double 'c) | {
"end_col": 59,
"end_line": 41,
"start_col": 38,
"start_line": 41
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y) | let op_Hat_Star = | false | null | false | rel_map2T (fun x y -> op_Multiply x y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.int",
"Prims.op_Multiply"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Star : _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | [] | FStar.Relational.Relational.op_Hat_Star | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | {
"end_col": 56,
"end_line": 52,
"start_col": 18,
"start_line": 52
} |
|
Prims.Tot | val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map1T f (R x1 x2) = R (f x1) (f x2) | val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = | false | null | false | R (f x1) (f x2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.double",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b) | [] | FStar.Relational.Relational.rel_map1T | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (_: 'a -> 'b) -> _: FStar.Relational.Relational.double 'a
-> FStar.Relational.Relational.double 'b | {
"end_col": 44,
"end_line": 32,
"start_col": 29,
"start_line": 32
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Plus = rel_map2T (fun x y -> x + y) | let op_Hat_Plus = | false | null | false | rel_map2T (fun x y -> x + y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.int",
"Prims.op_Addition"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Plus : _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | [] | FStar.Relational.Relational.op_Hat_Plus | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.int -> _: FStar.Relational.Relational.double Prims.int
-> FStar.Relational.Relational.double Prims.int | {
"end_col": 46,
"end_line": 50,
"start_col": 18,
"start_line": 50
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let snd_rel = rel_map1T snd | let snd_rel = | false | null | false | rel_map1T snd | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map1T",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"FStar.Relational.Relational.double"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val snd_rel : _: FStar.Relational.Relational.double (_ * _) -> FStar.Relational.Relational.double _ | [] | FStar.Relational.Relational.snd_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double (_ * _) -> FStar.Relational.Relational.double _ | {
"end_col": 27,
"end_line": 63,
"start_col": 14,
"start_line": 63
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_Hat_Slash = rel_map2T (fun x y -> x / y) | let op_Hat_Slash = | false | null | false | rel_map2T (fun x y -> x / y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.int",
"Prims.nonzero",
"Prims.op_Division"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Hat_Slash : _: FStar.Relational.Relational.double Prims.int ->
_: FStar.Relational.Relational.double Prims.nonzero
-> FStar.Relational.Relational.double Prims.int | [] | FStar.Relational.Relational.op_Hat_Slash | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
_: FStar.Relational.Relational.double Prims.int ->
_: FStar.Relational.Relational.double Prims.nonzero
-> FStar.Relational.Relational.double Prims.int | {
"end_col": 47,
"end_line": 53,
"start_col": 19,
"start_line": 53
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f) | let triple_rel (R a b) (R c d) (R e f) = | false | null | false | R (a, c, e) (b, d, f) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Relational.Relational.R",
"FStar.Pervasives.Native.tuple3"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val triple_rel : _: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel _ _
-> FStar.Relational.Relational.rel ((_ * _) * _) ((_ * _) * _) | [] | FStar.Relational.Relational.triple_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
_: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel _ _
-> FStar.Relational.Relational.rel ((_ * _) * _) ((_ * _) * _) | {
"end_col": 58,
"end_line": 61,
"start_col": 41,
"start_line": 61
} |
|
Prims.Tot | val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2) | val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = | false | null | false | R (f x1 y1 z1) (f x2 y2 z2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.double",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Relational.Relational.rel",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd) | [] | FStar.Relational.Relational.rel_map3T | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: 'a -> _: 'b -> _: 'c -> 'd) ->
_: FStar.Relational.Relational.double 'a ->
_: FStar.Relational.Relational.double 'b ->
_: FStar.Relational.Relational.double 'c
-> FStar.Relational.Relational.double 'd | {
"end_col": 75,
"end_line": 44,
"start_col": 48,
"start_line": 44
} |
Prims.GTot | val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2) | val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = | false | null | false | R (f x1 y1 z1) (f x2 y2 z2) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"sometrivial"
] | [
"FStar.Relational.Relational.double",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Relational.Relational.rel",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd) | [] | FStar.Relational.Relational.rel_map3G | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
f: (_: 'a -> _: 'b -> _: 'c -> Prims.GTot 'd) ->
_: FStar.Relational.Relational.double 'a ->
_: FStar.Relational.Relational.double 'b ->
_: FStar.Relational.Relational.double 'c
-> Prims.GTot (FStar.Relational.Relational.double 'd) | {
"end_col": 75,
"end_line": 47,
"start_col": 48,
"start_line": 47
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fst_rel = rel_map1T fst | let fst_rel = | false | null | false | rel_map1T fst | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map1T",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Relational.Relational.double"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fst_rel : _: FStar.Relational.Relational.double (_ * _) -> FStar.Relational.Relational.double _ | [] | FStar.Relational.Relational.fst_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double (_ * _) -> FStar.Relational.Relational.double _ | {
"end_col": 27,
"end_line": 62,
"start_col": 14,
"start_line": 62
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eq_rel = rel_map2Teq (fun (x y:bool) -> x = y) | let eq_rel = | false | null | false | rel_map2Teq (fun (x: bool) (y: bool) -> x = y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2Teq",
"Prims.bool",
"Prims.op_Equality"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *)
let and_rel = rel_map2T (fun x y -> x && y) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq_rel : _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | [] | FStar.Relational.Relational.eq_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | {
"end_col": 50,
"end_line": 68,
"start_col": 13,
"start_line": 68
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys) | let cons_rel (R x y) (R xs ys) = | false | null | false | R (x :: xs) (y :: ys) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel",
"Prims.list",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Relational.Relational.R",
"Prims.Cons"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a)) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cons_rel : _: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel (Prims.list _) (Prims.list _)
-> FStar.Relational.Relational.rel (Prims.list _) (Prims.list _) | [] | FStar.Relational.Relational.cons_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
_: FStar.Relational.Relational.rel _ _ ->
_: FStar.Relational.Relational.rel (Prims.list _) (Prims.list _)
-> FStar.Relational.Relational.rel (Prims.list _) (Prims.list _) | {
"end_col": 50,
"end_line": 58,
"start_col": 33,
"start_line": 58
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pair_rel (R a b) (R c d) = R (a,c) (b,d) | let pair_rel (R a b) (R c d) = | false | null | false | R (a, c) (b, d) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Relational.Relational.R",
"FStar.Pervasives.Native.tuple2"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pair_rel : _: FStar.Relational.Relational.rel _ _ -> _: FStar.Relational.Relational.rel _ _
-> FStar.Relational.Relational.rel (_ * _) (_ * _) | [] | FStar.Relational.Relational.pair_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.rel _ _ -> _: FStar.Relational.Relational.rel _ _
-> FStar.Relational.Relational.rel (_ * _) (_ * _) | {
"end_col": 44,
"end_line": 60,
"start_col": 31,
"start_line": 60
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let or_irel (R a b) = a || b | let or_irel (R a b) = | false | null | false | a || b | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel",
"Prims.bool",
"Prims.op_BarBar"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *)
let and_rel = rel_map2T (fun x y -> x && y)
let or_rel = rel_map2T (fun x y -> x || y)
let eq_rel = rel_map2Teq (fun (x y:bool) -> x = y)
(* Some convenient functions combining left and right side (for specification only) *) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val or_irel : _: FStar.Relational.Relational.rel Prims.bool Prims.bool -> Prims.bool | [] | FStar.Relational.Relational.or_irel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.rel Prims.bool Prims.bool -> Prims.bool | {
"end_col": 28,
"end_line": 72,
"start_col": 22,
"start_line": 72
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eq_irel (#t:eqtype) (x:(rel t t)) = match x with
| R a b -> a = b | let eq_irel (#t: eqtype) (x: (rel t t)) = | false | null | false | match x with | R a b -> a = b | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"Prims.eqtype",
"FStar.Relational.Relational.rel",
"Prims.op_Equality",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *)
let and_rel = rel_map2T (fun x y -> x && y)
let or_rel = rel_map2T (fun x y -> x || y)
let eq_rel = rel_map2Teq (fun (x y:bool) -> x = y)
(* Some convenient functions combining left and right side (for specification only) *)
let and_irel (R a b) = a && b | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq_irel : x: FStar.Relational.Relational.rel t t -> Prims.bool | [] | FStar.Relational.Relational.eq_irel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Relational.Relational.rel t t -> Prims.bool | {
"end_col": 18,
"end_line": 74,
"start_col": 40,
"start_line": 73
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let and_irel (R a b) = a && b | let and_irel (R a b) = | false | null | false | a && b | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel",
"Prims.bool",
"Prims.op_AmpAmp"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *)
let and_rel = rel_map2T (fun x y -> x && y)
let or_rel = rel_map2T (fun x y -> x || y)
let eq_rel = rel_map2Teq (fun (x y:bool) -> x = y) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val and_irel : _: FStar.Relational.Relational.rel Prims.bool Prims.bool -> Prims.bool | [] | FStar.Relational.Relational.and_irel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.rel Prims.bool Prims.bool -> Prims.bool | {
"end_col": 29,
"end_line": 71,
"start_col": 23,
"start_line": 71
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let and_rel = rel_map2T (fun x y -> x && y) | let and_rel = | false | null | false | rel_map2T (fun x y -> x && y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.bool",
"Prims.op_AmpAmp"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val and_rel : _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | [] | FStar.Relational.Relational.and_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | {
"end_col": 43,
"end_line": 66,
"start_col": 14,
"start_line": 66
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let or_rel = rel_map2T (fun x y -> x || y) | let or_rel = | false | null | false | rel_map2T (fun x y -> x || y) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.rel_map2T",
"Prims.bool",
"Prims.op_BarBar"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *) | false | true | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val or_rel : _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | [] | FStar.Relational.Relational.or_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: FStar.Relational.Relational.double Prims.bool -> _: FStar.Relational.Relational.double Prims.bool
-> FStar.Relational.Relational.double Prims.bool | {
"end_col": 42,
"end_line": 67,
"start_col": 13,
"start_line": 67
} |
|
Prims.GTot | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sel_rel1 (#a:Type) (h:double heap) (r:ref a) = rel_map2G sel h (twice r) | let sel_rel1 (#a: Type) (h: double heap) (r: ref a) = | false | null | false | rel_map2G sel h (twice r) | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"sometrivial"
] | [
"FStar.Relational.Relational.double",
"FStar.Monotonic.Heap.heap",
"FStar.Heap.ref",
"FStar.Relational.Relational.rel_map2G",
"FStar.Monotonic.Heap.mref",
"FStar.Heap.trivial_preorder",
"FStar.Monotonic.Heap.sel",
"FStar.Relational.Relational.twice"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *)
val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_::xs) (_::ys)) = R xs ys
let cons_rel (R x y) (R xs ys) = R (x::xs) (y::ys)
(* Some convenient tuple functions *)
let pair_rel (R a b) (R c d) = R (a,c) (b,d)
let triple_rel (R a b) (R c d) (R e f) = R (a,c,e) (b,d,f)
let fst_rel = rel_map1T fst
let snd_rel = rel_map1T snd
(* Some convenient boolean functions *)
let and_rel = rel_map2T (fun x y -> x && y)
let or_rel = rel_map2T (fun x y -> x || y)
let eq_rel = rel_map2Teq (fun (x y:bool) -> x = y)
(* Some convenient functions combining left and right side (for specification only) *)
let and_irel (R a b) = a && b
let or_irel (R a b) = a || b
let eq_irel (#t:eqtype) (x:(rel t t)) = match x with
| R a b -> a = b | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sel_rel1 : h: FStar.Relational.Relational.double FStar.Monotonic.Heap.heap -> r: FStar.Heap.ref a
-> Prims.GTot (FStar.Relational.Relational.double a) | [] | FStar.Relational.Relational.sel_rel1 | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | h: FStar.Relational.Relational.double FStar.Monotonic.Heap.heap -> r: FStar.Heap.ref a
-> Prims.GTot (FStar.Relational.Relational.double a) | {
"end_col": 77,
"end_line": 77,
"start_col": 52,
"start_line": 77
} |
|
Prims.Tot | val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a)) | [
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Relational",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tl_rel #a (R (_::xs) (_::ys)) = R xs ys | val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a))
let tl_rel #a (R (_ :: xs) (_ :: ys)) = | false | null | false | R xs ys | {
"checked_file": "FStar.Relational.Relational.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Relational.Relational.fst"
} | [
"total"
] | [
"FStar.Relational.Relational.double",
"Prims.list",
"Prims.l_and",
"Prims.b2t",
"Prims.uu___is_Cons",
"FStar.Relational.Relational.__proj__R__item__l",
"FStar.Relational.Relational.__proj__R__item__r",
"FStar.Relational.Relational.R"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Relational.Relational
open FStar.Heap
(* Relational Type constructor (Equivalent to pairs) *)
type rel (a:Type) (b:Type) : Type =
| R : l:a -> r:b -> rel a b
(* Some frequently used abbreviations *)
type double (t:Type) = rel t t
type eq (t:Type) = p:(double t){R?.l p == R?.r p}
let twice x = R x x
let tu = twice ()
(* functions to lift normal functions to Relational functions *)
val rel_map1T : ('a -> Tot 'b) -> (double 'a) -> Tot (double 'b)
let rel_map1T f (R x1 x2) = R (f x1) (f x2)
val rel_map2Teq : #a:eqtype -> #b:eqtype -> #c:Type -> (a -> b -> Tot c) -> (double a) -> (double b) -> Tot (double c)
let rel_map2Teq #a #b #c f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2T : ('a -> 'b -> Tot 'c) -> (double 'a) -> (double 'b) -> Tot (double 'c)
let rel_map2T f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map2G : ('a -> 'b -> GTot 'c) -> (double 'a) -> (double 'b) -> GTot (double 'c)
let rel_map2G f (R x1 x2) (R y1 y2) = R (f x1 y1) (f x2 y2)
val rel_map3T : ('a -> 'b -> 'c -> Tot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> Tot (double 'd)
let rel_map3T f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
val rel_map3G : ('a -> 'b -> 'c -> GTot 'd) -> (double 'a) -> (double 'b) -> (double 'c) -> GTot (double 'd)
let rel_map3G f (R x1 x2) (R y1 y2) (R z1 z2) = R (f x1 y1 z1) (f x2 y2 z2)
(* Some convenient arithmetic functions *)
let op_Hat_Plus = rel_map2T (fun x y -> x + y)
let op_Hat_Minus = rel_map2T (fun x y -> x - y)
let op_Hat_Star = rel_map2T (fun x y -> op_Multiply x y)
let op_Hat_Slash = rel_map2T (fun x y -> x / y)
(* Some convenient list functions *) | false | false | FStar.Relational.Relational.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tl_rel: #a:Type -> l:double (list a){Cons? (R?.l l) /\ Cons? (R?.r l)}-> Tot (double (list a)) | [] | FStar.Relational.Relational.tl_rel | {
"file_name": "ulib/legacy/FStar.Relational.Relational.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: FStar.Relational.Relational.double (Prims.list a) {Cons? (R?.l l) /\ Cons? (R?.r l)}
-> FStar.Relational.Relational.double (Prims.list a) | {
"end_col": 43,
"end_line": 57,
"start_col": 36,
"start_line": 57
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rt_subst = L.map rt_subst_elt | let rt_subst = | false | null | false | L.map rt_subst_elt | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.List.Tot.Base.map",
"Pulse.Syntax.Naming.subst_elt",
"FStar.Reflection.Typing.subst_elt",
"Pulse.Syntax.Naming.rt_subst_elt"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rt_subst : x: Prims.list Pulse.Syntax.Naming.subst_elt -> Prims.list FStar.Reflection.Typing.subst_elt | [] | Pulse.Syntax.Naming.rt_subst | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Prims.list Pulse.Syntax.Naming.subst_elt -> Prims.list FStar.Reflection.Typing.subst_elt | {
"end_col": 33,
"end_line": 368,
"start_col": 15,
"start_line": 368
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_st (t:st_term) = ln_st' t (-1) | let ln_st (t: st_term) = | false | null | false | ln_st' t (- 1) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Naming.ln_st'",
"Prims.op_Minus",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_st : t: Pulse.Syntax.Base.st_term -> Prims.bool | [] | Pulse.Syntax.Naming.ln_st | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> Prims.bool | {
"end_col": 37,
"end_line": 343,
"start_col": 24,
"start_line": 343
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst = list subst_elt | let subst = | false | null | false | list subst_elt | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Naming.subst_elt"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst : Type0 | [] | Pulse.Syntax.Naming.subst | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Type0 | {
"end_col": 26,
"end_line": 357,
"start_col": 12,
"start_line": 357
} |
|
Prims.Tot | val open_term_list' (t: list term) (v: term) (i: index) : Tot (list term) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ] | val open_term_list' (t: list term) (v: term) (i: index) : Tot (list term)
let open_term_list' (t: list term) (v: term) (i: index) : Tot (list term) = | false | null | false | subst_term_list t [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_list",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_term_list' (t: list term) (v: term) (i: index) : Tot (list term) | [] | Pulse.Syntax.Naming.open_term_list' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Prims.list Pulse.Syntax.Base.term | {
"end_col": 50,
"end_line": 453,
"start_col": 22,
"start_line": 453
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln (t:term) = ln' t (-1) | let ln (t: term) = | false | null | false | ln' t (- 1) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.ln'",
"Prims.op_Minus",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln : t: Pulse.Syntax.Base.term -> Prims.bool | [] | Pulse.Syntax.Naming.ln | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> Prims.bool | {
"end_col": 28,
"end_line": 342,
"start_col": 18,
"start_line": 342
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0 | let open_st_term_nv t nv = | false | null | false | open_st_term' t (U.term_of_nvar nv) 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.nvar",
"Pulse.Syntax.Naming.open_st_term'",
"Pulse.Syntax.Pure.term_of_nvar"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_st_term_nv : t: Pulse.Syntax.Base.st_term -> nv: Pulse.Syntax.Base.nvar -> Pulse.Syntax.Base.st_term | [] | Pulse.Syntax.Naming.open_st_term_nv | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> nv: Pulse.Syntax.Base.nvar -> Pulse.Syntax.Base.st_term | {
"end_col": 41,
"end_line": 628,
"start_col": 4,
"start_line": 628
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i] | let close_term_pairs' (t: list (term * term)) (x: var) (i: index) = | false | null | false | subst_term_pairs t [ND x i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_pairs",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term_pairs' : t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) ->
x: Pulse.Syntax.Base.var ->
i: Pulse.Syntax.Base.index
-> Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | [] | Pulse.Syntax.Naming.close_term_pairs' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) ->
x: Pulse.Syntax.Base.var ->
i: Pulse.Syntax.Base.index
-> Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | {
"end_col": 29,
"end_line": 482,
"start_col": 2,
"start_line": 482
} |
|
Prims.Tot | val open_comp' (c: comp) (v: term) (i: index) : comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ] | val open_comp' (c: comp) (v: term) (i: index) : comp
let open_comp' (c: comp) (v: term) (i: index) : comp = | false | null | false | subst_comp c [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_comp",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_comp' (c: comp) (v: term) (i: index) : comp | [] | Pulse.Syntax.Naming.open_comp' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.comp | {
"end_col": 25,
"end_line": 435,
"start_col": 2,
"start_line": 435
} |
Prims.Tot | val open_term_opt' (t: option term) (v: term) (i: index) : Tot (option term) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ] | val open_term_opt' (t: option term) (v: term) (i: index) : Tot (option term)
let open_term_opt' (t: option term) (v: term) (i: index) : Tot (option term) = | false | null | false | subst_term_opt t [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_opt",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_term_opt' (t: option term) (v: term) (i: index) : Tot (option term) | [] | Pulse.Syntax.Naming.open_term_opt' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term ->
v: Pulse.Syntax.Base.term ->
i: Pulse.Syntax.Base.index
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.term | {
"end_col": 51,
"end_line": 444,
"start_col": 24,
"start_line": 444
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_binder b v i =
subst_binder b [ ND v i ] | let close_binder b v i = | false | null | false | subst_binder b [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.var",
"Prims.nat",
"Pulse.Syntax.Naming.subst_binder",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_binder : b: Pulse.Syntax.Base.binder -> v: Pulse.Syntax.Base.var -> i: Prims.nat -> Pulse.Syntax.Base.binder | [] | Pulse.Syntax.Naming.close_binder | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | b: Pulse.Syntax.Base.binder -> v: Pulse.Syntax.Base.var -> i: Prims.nat -> Pulse.Syntax.Base.binder | {
"end_col": 27,
"end_line": 652,
"start_col": 2,
"start_line": 652
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i] | let close_proof_hint' (ht: proof_hint_type) (x: var) (i: index) = | false | null | false | subst_proof_hint ht [ND x i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.proof_hint_type",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_proof_hint",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_proof_hint' : ht: Pulse.Syntax.Base.proof_hint_type -> x: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.proof_hint_type | [] | Pulse.Syntax.Naming.close_proof_hint' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ht: Pulse.Syntax.Base.proof_hint_type -> x: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.proof_hint_type | {
"end_col": 30,
"end_line": 488,
"start_col": 2,
"start_line": 488
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i} | let open_binder b v i = | false | null | false | { b with binder_ty = open_term' b.binder_ty v i } | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Base.Mkbinder",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss} | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_binder : b: Pulse.Syntax.Base.binder -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.binder | [] | Pulse.Syntax.Naming.open_binder | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | b: Pulse.Syntax.Base.binder -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.binder | {
"end_col": 46,
"end_line": 459,
"start_col": 3,
"start_line": 459
} |
|
Prims.Tot | val subst_st_comp (s: st_comp) (ss: subst) : st_comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) } | val subst_st_comp (s: st_comp) (ss: subst) : st_comp
let subst_st_comp (s: st_comp) (ss: subst) : st_comp = | false | null | false | {
s with
res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss)
} | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Naming.subst",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Pulse.Syntax.Naming.shift_subst"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp = | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_st_comp (s: st_comp) (ss: subst) : st_comp | [] | Pulse.Syntax.Naming.subst_st_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.st_comp -> ss: Pulse.Syntax.Naming.subst -> Pulse.Syntax.Base.st_comp | {
"end_col": 51,
"end_line": 413,
"start_col": 3,
"start_line": 411
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v] | let open_term_pairs' (t: list (term * term)) (v: term) (i: index) = | false | null | false | subst_term_pairs t [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_pairs",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss } | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_term_pairs' : t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) ->
v: Pulse.Syntax.Base.term ->
i: Pulse.Syntax.Base.index
-> Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | [] | Pulse.Syntax.Naming.open_term_pairs' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) ->
v: Pulse.Syntax.Base.term ->
i: Pulse.Syntax.Base.index
-> Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | {
"end_col": 29,
"end_line": 479,
"start_col": 2,
"start_line": 479
} |
|
Prims.Tot | val close_comp' (c: comp) (v: var) (i: index) : comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ] | val close_comp' (c: comp) (v: var) (i: index) : comp
let close_comp' (c: comp) (v: var) (i: index) : comp = | false | null | false | subst_comp c [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_comp",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_comp' (c: comp) (v: var) (i: index) : comp | [] | Pulse.Syntax.Naming.close_comp' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> v: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.comp | {
"end_col": 25,
"end_line": 643,
"start_col": 2,
"start_line": 643
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_subst = shift_subst_n 1 | let shift_subst = | false | null | false | shift_subst_n 1 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Naming.shift_subst_n"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_subst : x: Prims.list Pulse.Syntax.Naming.subst_elt -> Prims.list Pulse.Syntax.Naming.subst_elt | [] | Pulse.Syntax.Naming.shift_subst | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: Prims.list Pulse.Syntax.Naming.subst_elt -> Prims.list Pulse.Syntax.Naming.subst_elt | {
"end_col": 33,
"end_line": 361,
"start_col": 18,
"start_line": 361
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term t v = close_term' t v 0 | let close_term t v = | false | null | false | close_term' t v 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.close_term'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ]
let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term : t: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.term | [] | Pulse.Syntax.Naming.close_term | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.term | {
"end_col": 38,
"end_line": 657,
"start_col": 21,
"start_line": 657
} |
|
Prims.Tot | val close_st_term' (t: st_term) (v: var) (i: index) : st_term | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ] | val close_st_term' (t: st_term) (v: var) (i: index) : st_term
let close_st_term' (t: st_term) (v: var) (i: index) : st_term = | false | null | false | subst_st_term t [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_st_term",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_st_term' (t: st_term) (v: var) (i: index) : st_term | [] | Pulse.Syntax.Naming.close_st_term' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> v: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.st_term | {
"end_col": 28,
"end_line": 655,
"start_col": 2,
"start_line": 655
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ] | let open_term' (t v: term) (i: index) = | false | null | false | subst_term t [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss)) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_term' : t: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.term | [] | Pulse.Syntax.Naming.open_term' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.term | {
"end_col": 25,
"end_line": 406,
"start_col": 2,
"start_line": 406
} |
|
Prims.Tot | val close_term_opt' (t: option term) (v: var) (i: index) : option term | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ] | val close_term_opt' (t: option term) (v: var) (i: index) : option term
let close_term_opt' (t: option term) (v: var) (i: index) : option term = | false | null | false | subst_term_opt t [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_opt",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term_opt' (t: option term) (v: var) (i: index) : option term | [] | Pulse.Syntax.Naming.close_term_opt' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term ->
v: Pulse.Syntax.Base.var ->
i: Pulse.Syntax.Base.index
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.term | {
"end_col": 29,
"end_line": 646,
"start_col": 2,
"start_line": 646
} |
Prims.Tot | val close_term_list' (t: list term) (v: var) (i: index) : list term | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ] | val close_term_list' (t: list term) (v: var) (i: index) : list term
let close_term_list' (t: list term) (v: var) (i: index) : list term = | false | null | false | subst_term_list t [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term_list",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term_list' (t: list term) (v: var) (i: index) : list term | [] | Pulse.Syntax.Naming.close_term_list' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Prims.list Pulse.Syntax.Base.term | {
"end_col": 30,
"end_line": 649,
"start_col": 2,
"start_line": 649
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_st_term t v = close_st_term' t v 0 | let close_st_term t v = | false | null | false | close_st_term' t v 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.close_st_term'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ]
let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_st_term : t: Pulse.Syntax.Base.st_term -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.st_term | [] | Pulse.Syntax.Naming.close_st_term | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.st_term | {
"end_col": 44,
"end_line": 658,
"start_col": 24,
"start_line": 658
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_subst_n (n:nat) = L.map (shift_subst_elt n) | let shift_subst_n (n: nat) = | false | null | false | L.map (shift_subst_elt n) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.nat",
"FStar.List.Tot.Base.map",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.shift_subst_elt",
"Prims.list"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_subst_n : n: Prims.nat -> x: Prims.list Pulse.Syntax.Naming.subst_elt
-> Prims.list Pulse.Syntax.Naming.subst_elt | [] | Pulse.Syntax.Naming.shift_subst_n | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | n: Prims.nat -> x: Prims.list Pulse.Syntax.Naming.subst_elt
-> Prims.list Pulse.Syntax.Naming.subst_elt | {
"end_col": 53,
"end_line": 359,
"start_col": 28,
"start_line": 359
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v] | let open_proof_hint' (ht: proof_hint_type) (v: term) (i: index) = | false | null | false | subst_proof_hint ht [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.proof_hint_type",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_proof_hint",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_proof_hint' : ht: Pulse.Syntax.Base.proof_hint_type -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.proof_hint_type | [] | Pulse.Syntax.Naming.open_proof_hint' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ht: Pulse.Syntax.Base.proof_hint_type -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.proof_hint_type | {
"end_col": 30,
"end_line": 485,
"start_col": 2,
"start_line": 485
} |
|
Prims.Tot | val open_st_comp' (s: st_comp) (v: term) (i: index) : st_comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ] | val open_st_comp' (s: st_comp) (v: term) (i: index) : st_comp
let open_st_comp' (s: st_comp) (v: term) (i: index) : st_comp = | false | null | false | subst_st_comp s [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_st_comp",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) } | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_st_comp' (s: st_comp) (v: term) (i: index) : st_comp | [] | Pulse.Syntax.Naming.open_st_comp' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.st_comp -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.st_comp | {
"end_col": 28,
"end_line": 416,
"start_col": 2,
"start_line": 416
} |
Prims.Tot | val ln_st_comp (s: st_comp) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) | val ln_st_comp (s: st_comp) (i: int) : bool
let ln_st_comp (s: st_comp) (i: int) : bool = | false | null | false | ln' s.res i && ln' s.pre i && ln' s.post (i + 1) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_comp",
"Prims.int",
"Prims.op_AmpAmp",
"Pulse.Syntax.Naming.ln'",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Prims.op_Addition",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_st_comp (s: st_comp) (i: int) : bool | [] | Pulse.Syntax.Naming.ln_st_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.st_comp -> i: Prims.int -> Prims.bool | {
"end_col": 20,
"end_line": 175,
"start_col": 2,
"start_line": 173
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_c (c:comp) = ln_c' c (-1) | let ln_c (c: comp) = | false | null | false | ln_c' c (- 1) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Naming.ln_c'",
"Prims.op_Minus",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_c : c: Pulse.Syntax.Base.comp -> Prims.bool | [] | Pulse.Syntax.Naming.ln_c | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> Prims.bool | {
"end_col": 32,
"end_line": 344,
"start_col": 20,
"start_line": 344
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0 | let open_term_nv t nv = | false | null | false | open_term' t (U.term_of_nvar nv) 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.nvar",
"Pulse.Syntax.Naming.open_term'",
"Pulse.Syntax.Pure.term_of_nvar"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_term_nv : t: Pulse.Syntax.Base.term -> nv: Pulse.Syntax.Base.nvar -> Pulse.Syntax.Base.term | [] | Pulse.Syntax.Naming.open_term_nv | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> nv: Pulse.Syntax.Base.nvar -> Pulse.Syntax.Base.term | {
"end_col": 38,
"end_line": 621,
"start_col": 4,
"start_line": 621
} |
|
Prims.Tot | val open_st_term' (t: st_term) (v: term) (i: index) : st_term | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ] | val open_st_term' (t: st_term) (v: term) (i: index) : st_term
let open_st_term' (t: st_term) (v: term) (i: index) : st_term = | false | null | false | subst_st_term t [DT i v] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_st_term",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_st_term' (t: st_term) (v: term) (i: index) : st_term | [] | Pulse.Syntax.Naming.open_st_term' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> v: Pulse.Syntax.Base.term -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.st_term | {
"end_col": 28,
"end_line": 618,
"start_col": 2,
"start_line": 618
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let open_comp_with (c:comp) (x:term) = open_comp' c x 0 | let open_comp_with (c: comp) (x: term) = | false | null | false | open_comp' c x 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.open_comp'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val open_comp_with : c: Pulse.Syntax.Base.comp -> x: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | [] | Pulse.Syntax.Naming.open_comp_with | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> x: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp | {
"end_col": 55,
"end_line": 634,
"start_col": 39,
"start_line": 634
} |
|
Prims.Tot | val close_st_comp' (s: st_comp) (v: var) (i: index) : st_comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ] | val close_st_comp' (s: st_comp) (v: var) (i: index) : st_comp
let close_st_comp' (s: st_comp) (v: var) (i: index) : st_comp = | false | null | false | subst_st_comp s [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_st_comp",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_st_comp' (s: st_comp) (v: var) (i: index) : st_comp | [] | Pulse.Syntax.Naming.close_st_comp' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.st_comp -> v: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.st_comp | {
"end_col": 28,
"end_line": 640,
"start_col": 2,
"start_line": 640
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss} | let subst_binder b ss = | false | null | false | { b with binder_ty = subst_term b.binder_ty ss } | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Naming.subst",
"Pulse.Syntax.Base.Mkbinder",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ] | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_binder : b: Pulse.Syntax.Base.binder -> ss: Pulse.Syntax.Naming.subst -> Pulse.Syntax.Base.binder | [] | Pulse.Syntax.Naming.subst_binder | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | b: Pulse.Syntax.Base.binder -> ss: Pulse.Syntax.Naming.subst -> Pulse.Syntax.Base.binder | {
"end_col": 45,
"end_line": 456,
"start_col": 3,
"start_line": 456
} |
|
Prims.Tot | val close_term' (t: term) (v: var) (i: index) : term | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ] | val close_term' (t: term) (v: var) (i: index) : term
let close_term' (t: term) (v: var) (i: index) : term = | false | null | false | subst_term t [ND v i] | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.index",
"Pulse.Syntax.Naming.subst_term",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.ND",
"Prims.Nil"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0 | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term' (t: term) (v: var) (i: index) : term | [] | Pulse.Syntax.Naming.close_term' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> v: Pulse.Syntax.Base.var -> i: Pulse.Syntax.Base.index
-> Pulse.Syntax.Base.term | {
"end_col": 25,
"end_line": 637,
"start_col": 2,
"start_line": 637
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_comp t v = close_comp' t v 0 | let close_comp t v = | false | null | false | close_comp' t v 0 | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.close_comp'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ]
let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ]
let close_term t v = close_term' t v 0 | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_comp : t: Pulse.Syntax.Base.comp -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.comp | [] | Pulse.Syntax.Naming.close_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.comp -> v: Pulse.Syntax.Base.var -> Pulse.Syntax.Base.comp | {
"end_col": 38,
"end_line": 659,
"start_col": 21,
"start_line": 659
} |
|
Prims.Tot | val ln_c' (c: comp) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i | val ln_c' (c: comp) (i: int) : bool
let ln_c' (c: comp) (i: int) : bool = | false | null | false | match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s | C_STGhost inames s -> ln' inames i && ln_st_comp s i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Prims.int",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.ln'",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Naming.ln_st_comp",
"Prims.op_AmpAmp",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_c' (c: comp) (i: int) : bool | [] | Pulse.Syntax.Naming.ln_c' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> i: Prims.int -> Prims.bool | {
"end_col": 20,
"end_line": 186,
"start_col": 4,
"start_line": 180
} |
Prims.Tot | val subst_comp (c: comp) (ss: subst) : comp | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss) | val subst_comp (c: comp) (ss: subst) : comp
let subst_comp (c: comp) (ss: subst) : comp = | false | null | false | match c with
| C_Tot t -> C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s -> C_STAtomic (subst_term inames ss) (subst_st_comp s ss)
| C_STGhost inames s -> C_STGhost (subst_term inames ss) (subst_st_comp s ss) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Naming.subst",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.C_Tot",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Naming.subst_st_comp",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.C_STGhost"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_comp (c: comp) (ss: subst) : comp | [] | Pulse.Syntax.Naming.subst_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> ss: Pulse.Syntax.Naming.subst -> Pulse.Syntax.Base.comp | {
"end_col": 36,
"end_line": 432,
"start_col": 4,
"start_line": 420
} |
Prims.Tot | val ln_list' (t: list term) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i | val ln_list' (t: list term) (i: int) : bool
let rec ln_list' (t: list term) (i: int) : bool = | false | null | false | match t with
| [] -> true
| hd :: tl -> ln' hd i && ln_list' tl i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"Prims.int",
"Prims.op_AmpAmp",
"Pulse.Syntax.Naming.ln'",
"Pulse.Syntax.Naming.ln_list'",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_list' (t: list term) (i: int) : bool | [
"recursion"
] | Pulse.Syntax.Naming.ln_list' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list Pulse.Syntax.Base.term -> i: Prims.int -> Prims.bool | {
"end_col": 39,
"end_line": 196,
"start_col": 2,
"start_line": 194
} |
Prims.Tot | val subst_term_pairs (t: list (term & term)) (ss: subst) : Tot (list (term & term)) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss | val subst_term_pairs (t: list (term & term)) (ss: subst) : Tot (list (term & term))
let rec subst_term_pairs (t: list (term & term)) (ss: subst) : Tot (list (term & term)) = | false | null | false | match t with
| [] -> []
| (t1, t2) :: tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.subst",
"Prims.Nil",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Naming.subst_term_pairs"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_term_pairs (t: list (term & term)) (ss: subst) : Tot (list (term & term)) | [
"recursion"
] | Pulse.Syntax.Naming.subst_term_pairs | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) -> ss: Pulse.Syntax.Naming.subst
-> Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | {
"end_col": 84,
"end_line": 465,
"start_col": 4,
"start_line": 463
} |
Prims.Tot | val ln_proof_hint' (ht: proof_hint_type) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i | val ln_proof_hint' (ht: proof_hint_type) (i: int) : bool
let ln_proof_hint' (ht: proof_hint_type) (i: int) : bool = | false | null | false | match ht with
| ASSERT { p = p } | UNFOLD { p = p } | FOLD { p = p } -> ln' p i
| RENAME { pairs = pairs ; goal = goal } -> ln_terms' pairs i && ln_opt' goal i
| REWRITE { t1 = t1 ; t2 = t2 } -> ln' t1 i && ln' t2 i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.proof_hint_type",
"Prims.int",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Naming.ln'",
"FStar.Pervasives.Native.option",
"Prims.list",
"Prims.string",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Prims.op_AmpAmp",
"Pulse.Syntax.Naming.ln_terms'",
"Pulse.Syntax.Naming.ln_opt'",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_proof_hint' (ht: proof_hint_type) (i: int) : bool | [] | Pulse.Syntax.Naming.ln_proof_hint' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ht: Pulse.Syntax.Base.proof_hint_type -> i: Prims.int -> Prims.bool | {
"end_col": 12,
"end_line": 213,
"start_col": 2,
"start_line": 204
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | let shift_subst_elt (n: nat) = | false | null | false | function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.nat",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.DT",
"Prims.op_Addition",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.NT",
"Pulse.Syntax.Naming.ND"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_subst_elt : n: Prims.nat -> _: Pulse.Syntax.Naming.subst_elt -> Pulse.Syntax.Naming.subst_elt | [] | Pulse.Syntax.Naming.shift_subst_elt | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | n: Prims.nat -> _: Pulse.Syntax.Naming.subst_elt -> Pulse.Syntax.Naming.subst_elt | {
"end_col": 26,
"end_line": 355,
"start_col": 30,
"start_line": 352
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i | let rt_subst_elt = | false | null | false | function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Naming.subst_elt",
"Prims.nat",
"Pulse.Syntax.Base.term",
"FStar.Reflection.Typing.DT",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Syntax.Base.var",
"FStar.Reflection.Typing.NT",
"FStar.Reflection.Typing.ND",
"FStar.Reflection.Typing.subst_elt"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1 | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rt_subst_elt : _: Pulse.Syntax.Naming.subst_elt -> FStar.Reflection.Typing.subst_elt | [] | Pulse.Syntax.Naming.rt_subst_elt | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Pulse.Syntax.Naming.subst_elt -> FStar.Reflection.Typing.subst_elt | {
"end_col": 23,
"end_line": 366,
"start_col": 19,
"start_line": 363
} |
|
Prims.Tot | val subst_proof_hint (ht: proof_hint_type) (ss: subst) : proof_hint_type | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss } | val subst_proof_hint (ht: proof_hint_type) (ss: subst) : proof_hint_type
let subst_proof_hint (ht: proof_hint_type) (ss: subst) : proof_hint_type = | false | null | false | match ht with
| ASSERT { p = p } -> ASSERT ({ p = subst_term p ss })
| UNFOLD { names = names ; p = p } -> UNFOLD ({ names = names; p = subst_term p ss })
| FOLD { names = names ; p = p } -> FOLD ({ names = names; p = subst_term p ss })
| RENAME { pairs = pairs ; goal = goal } ->
RENAME ({ pairs = subst_term_pairs pairs ss; goal = subst_term_opt goal ss })
| REWRITE { t1 = t1 ; t2 = t2 } -> REWRITE ({ t1 = subst_term t1 ss; t2 = subst_term t2 ss }) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.proof_hint_type",
"Pulse.Syntax.Naming.subst",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.ASSERT",
"Pulse.Syntax.Base.Mkproof_hint_type__ASSERT__payload",
"Pulse.Syntax.Naming.subst_term",
"FStar.Pervasives.Native.option",
"Prims.list",
"Prims.string",
"Pulse.Syntax.Base.UNFOLD",
"Pulse.Syntax.Base.Mkproof_hint_type__UNFOLD__payload",
"Pulse.Syntax.Base.FOLD",
"Pulse.Syntax.Base.Mkproof_hint_type__FOLD__payload",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.RENAME",
"Pulse.Syntax.Base.Mkproof_hint_type__RENAME__payload",
"Pulse.Syntax.Naming.subst_term_pairs",
"Pulse.Syntax.Naming.subst_term_opt",
"Pulse.Syntax.Base.REWRITE",
"Pulse.Syntax.Base.Mkproof_hint_type__REWRITE__payload"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_proof_hint (ht: proof_hint_type) (ss: subst) : proof_hint_type | [] | Pulse.Syntax.Naming.subst_proof_hint | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ht: Pulse.Syntax.Base.proof_hint_type -> ss: Pulse.Syntax.Naming.subst
-> Pulse.Syntax.Base.proof_hint_type | {
"end_col": 59,
"end_line": 476,
"start_col": 4,
"start_line": 469
} |
Prims.Tot | val subst_term (t: term) (ss: subst) : Tot term (decreases t) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss)) | val subst_term (t: term) (ss: subst) : Tot term (decreases t)
let rec subst_term (t: term) (ss: subst) : Tot term (decreases t) = | false | null | false | let w t' = with_range t' t.range in
match t.t with
| Tm_VProp | Tm_Emp | Tm_Inames | Tm_EmpInames | Tm_Unknown -> t
| Tm_Pure p -> w (Tm_Pure (subst_term p ss))
| Tm_Star l r -> w (Tm_Star (subst_term l ss) (subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u
({ b with binder_ty = subst_term b.binder_ty ss })
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u
({ b with binder_ty = subst_term b.binder_ty ss })
(subst_term body (shift_subst ss)))
| Tm_FStar t -> w (Tm_FStar (subst_host_term t ss)) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total",
""
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.subst",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.Tm_Pure",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Base.Tm_Star",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.Tm_ExistsSL",
"Pulse.Syntax.Base.Mkbinder",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname",
"Pulse.Syntax.Naming.shift_subst",
"Pulse.Syntax.Base.Tm_ForallSL",
"Pulse.Syntax.Base.host_term",
"Pulse.Syntax.Base.Tm_FStar",
"Pulse.Syntax.Naming.subst_host_term",
"Pulse.Syntax.Base.term'",
"Pulse.Syntax.Base.with_range",
"Pulse.Syntax.Base.__proj__Mkterm__item__range"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_term (t: term) (ss: subst) : Tot term (decreases t) | [
"recursion"
] | Pulse.Syntax.Naming.subst_term | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> ss: Pulse.Syntax.Naming.subst -> Prims.Tot Pulse.Syntax.Base.term | {
"end_col": 41,
"end_line": 403,
"start_col": 3,
"start_line": 379
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_st_term_n t vs =
let rec aux (i:nat) (vs:list var) (t:st_term) : Tot st_term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
aux (i+1) vs (close_st_term' t v i)
in
aux 0 (List.rev vs) t | let close_st_term_n t vs = | false | null | false | let rec aux (i: nat) (vs: list var) (t: st_term) : Tot st_term (decreases vs) =
match vs with
| [] -> t
| v :: vs -> aux (i + 1) vs (close_st_term' t v i)
in
aux 0 (List.rev vs) t | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_term",
"Prims.list",
"Pulse.Syntax.Base.var",
"FStar.List.Tot.Base.rev",
"Prims.nat",
"Prims.op_Addition",
"Pulse.Syntax.Naming.close_st_term'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ]
let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ]
let close_term t v = close_term' t v 0
let close_st_term t v = close_st_term' t v 0
let close_comp t v = close_comp' t v 0
let close_term_n t vs =
let rec aux (i:nat) (vs:list var) (t:term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
aux (i+1) vs (close_term' t v i)
in
aux 0 (List.rev vs) t | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_st_term_n : t: Pulse.Syntax.Base.st_term -> vs: Prims.list Pulse.Syntax.Base.var -> Pulse.Syntax.Base.st_term | [] | Pulse.Syntax.Naming.close_st_term_n | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.st_term -> vs: Prims.list Pulse.Syntax.Base.var -> Pulse.Syntax.Base.st_term | {
"end_col": 23,
"end_line": 677,
"start_col": 26,
"start_line": 670
} |
|
Prims.Tot | val freevars_st_comp (s: st_comp) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post | val freevars_st_comp (s: st_comp) : Set.set var
let freevars_st_comp (s: st_comp) : Set.set var = | false | null | false | ((freevars s.res) `Set.union` (freevars s.pre)) `Set.union` (freevars s.post) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.st_comp",
"FStar.Set.union",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_st_comp (s: st_comp) : Set.set var | [] | Pulse.Syntax.Naming.freevars_st_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | s: Pulse.Syntax.Base.st_comp -> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 17,
"end_line": 35,
"start_col": 2,
"start_line": 33
} |
Prims.Tot | val freevars_proof_hint (ht: proof_hint_type) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2) | val freevars_proof_hint (ht: proof_hint_type) : Set.set var
let freevars_proof_hint (ht: proof_hint_type) : Set.set var = | false | null | false | match ht with
| ASSERT { p = p } | FOLD { p = p } | UNFOLD { p = p } -> freevars p
| RENAME { pairs = pairs ; goal = goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1 = t1 ; t2 = t2 } -> Set.union (freevars t1) (freevars t2) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.proof_hint_type",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Naming.freevars",
"FStar.Pervasives.Native.option",
"Prims.list",
"Prims.string",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"FStar.Set.union",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Naming.freevars_pairs",
"Pulse.Syntax.Naming.freevars_term_opt",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_proof_hint (ht: proof_hint_type) : Set.set var | [] | Pulse.Syntax.Naming.freevars_proof_hint | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | ht: Pulse.Syntax.Base.proof_hint_type -> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 41,
"end_line": 72,
"start_col": 2,
"start_line": 65
} |
Prims.Tot | val freevars_term_opt (t: option term) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t | val freevars_term_opt (t: option term) : Set.set var
let freevars_term_opt (t: option term) : Set.set var = | false | null | false | freevars_opt freevars t | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.freevars_opt",
"Pulse.Syntax.Naming.freevars",
"FStar.Set.set",
"Pulse.Syntax.Base.var"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_term_opt (t: option term) : Set.set var | [] | Pulse.Syntax.Naming.freevars_term_opt | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 25,
"end_line": 52,
"start_col": 2,
"start_line": 52
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let close_term_n t vs =
let rec aux (i:nat) (vs:list var) (t:term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v::vs ->
aux (i+1) vs (close_term' t v i)
in
aux 0 (List.rev vs) t | let close_term_n t vs = | false | null | false | let rec aux (i: nat) (vs: list var) (t: term) : Tot term (decreases vs) =
match vs with
| [] -> t
| v :: vs -> aux (i + 1) vs (close_term' t v i)
in
aux 0 (List.rev vs) t | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Prims.list",
"Pulse.Syntax.Base.var",
"FStar.List.Tot.Base.rev",
"Prims.nat",
"Prims.op_Addition",
"Pulse.Syntax.Naming.close_term'"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss
let open_term_list' (t:list term) (v:term) (i:index)
: Tot (list term) = subst_term_list t [ DT i v ]
let subst_binder b ss =
{b with binder_ty=subst_term b.binder_ty ss}
let open_binder b v i =
{b with binder_ty=open_term' b.binder_ty v i}
let rec subst_term_pairs (t:list (term & term)) (ss:subst)
: Tot (list (term & term))
= match t with
| [] -> []
| (t1, t2)::tl -> (subst_term t1 ss, subst_term t2 ss) :: subst_term_pairs tl ss
let subst_proof_hint (ht:proof_hint_type) (ss:subst)
: proof_hint_type
= match ht with
| ASSERT { p } -> ASSERT { p=subst_term p ss }
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
| RENAME { pairs; goal } -> RENAME { pairs=subst_term_pairs pairs ss;
goal=subst_term_opt goal ss }
| REWRITE { t1; t2 } -> REWRITE { t1=subst_term t1 ss;
t2=subst_term t2 ss }
let open_term_pairs' (t:list (term * term)) (v:term) (i:index) =
subst_term_pairs t [DT i v]
let close_term_pairs' (t:list (term * term)) (x:var) (i:index) =
subst_term_pairs t [ND x i]
let open_proof_hint' (ht:proof_hint_type) (v:term) (i:index) =
subst_proof_hint ht [DT i v]
let close_proof_hint' (ht:proof_hint_type) (x:var) (i:index) =
subst_proof_hint ht [ND x i]
let rec subst_pat (p:pattern) (ss:subst)
: Tot pattern (decreases p)
= match p with
| Pat_Constant _
| Pat_Dot_Term None ->
p
| Pat_Var n t ->
let t = RU.map_seal t (fun t -> RT.subst_term t (rt_subst ss)) in
Pat_Var n t
| Pat_Dot_Term (Some e) ->
Pat_Dot_Term (Some (subst_term e ss))
| Pat_Cons d args ->
let args = subst_pat_args args ss in
Pat_Cons d args
and subst_pat_args (args:list (pattern & bool)) (ss:subst)
: Tot (list (pattern & bool)) (decreases args)
= match args with
| [] -> []
| (arg, b)::tl ->
let arg' = subst_pat arg ss in
let tl = subst_pat_args tl (shift_subst_n (pattern_shift_n arg) ss) in
(arg', b)::tl
let rec subst_st_term (t:st_term) (ss:subst)
: Tot st_term (decreases t)
= let t' =
match t.term with
| Tm_Return { ctag; insert_eq; term } ->
Tm_Return { ctag; insert_eq; term=subst_term term ss }
| Tm_Abs { b; q; ascription; body } ->
Tm_Abs { b=subst_binder b ss;
q;
ascription=subst_comp ascription (shift_subst ss);
body=subst_st_term body (shift_subst ss) }
| Tm_STApp { head; arg_qual; arg } ->
Tm_STApp { head = subst_term head ss;
arg_qual;
arg=subst_term arg ss }
| Tm_Bind { binder; head; body } ->
Tm_Bind { binder = subst_binder binder ss;
head = subst_st_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_TotBind { binder; head; body } ->
Tm_TotBind { binder = subst_binder binder ss;
head = subst_term head ss;
body = subst_st_term body (shift_subst ss) }
| Tm_If { b; then_; else_; post } ->
Tm_If { b = subst_term b ss;
then_ = subst_st_term then_ ss;
else_ = subst_st_term else_ ss;
post = subst_term_opt post (shift_subst ss) }
| Tm_Match { sc; returns_; brs } ->
Tm_Match { sc = subst_term sc ss;
returns_ = subst_term_opt returns_ ss;
brs = subst_branches t ss brs }
| Tm_IntroPure { p } ->
Tm_IntroPure { p = subst_term p ss }
| Tm_ElimExists { p } ->
Tm_ElimExists { p = subst_term p ss }
| Tm_IntroExists { p; witnesses } ->
Tm_IntroExists { p = subst_term p ss;
witnesses = subst_term_list witnesses ss }
| Tm_While { invariant; condition; body; condition_var } ->
Tm_While { invariant = subst_term invariant (shift_subst ss);
condition = subst_st_term condition ss;
body = subst_st_term body ss;
condition_var }
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Tm_Par { pre1=subst_term pre1 ss;
body1=subst_st_term body1 ss;
post1=subst_term post1 (shift_subst ss);
pre2=subst_term pre2 ss;
body2=subst_st_term body2 ss;
post2=subst_term post2 (shift_subst ss) }
| Tm_WithLocal { binder; initializer; body } ->
Tm_WithLocal { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
body = subst_st_term body (shift_subst ss) }
| Tm_WithLocalArray { binder; initializer; length; body } ->
Tm_WithLocalArray { binder = subst_binder binder ss;
initializer = subst_term initializer ss;
length = subst_term length ss;
body = subst_st_term body (shift_subst ss) }
| Tm_Rewrite { t1; t2 } ->
Tm_Rewrite { t1 = subst_term t1 ss;
t2 = subst_term t2 ss }
| Tm_Admit { ctag; u; typ; post } ->
Tm_Admit { ctag;
u;
typ=subst_term typ ss;
post=subst_term_opt post (shift_subst ss) }
| Tm_ProofHintWithBinders { hint_type; binders; t} ->
let n = L.length binders in
let ss = shift_subst_n n ss in
Tm_ProofHintWithBinders { binders;
hint_type=subst_proof_hint hint_type ss;
t = subst_st_term t ss }
in
{ t with term = t' }
and subst_branches (t:st_term) (ss:subst) (brs : list branch{brs << t})
: Tot (list branch) (decreases brs)
= map_dec t brs (fun br -> subst_branch ss br)
and subst_branch (ss:subst) (b : pattern & st_term) : Tot (pattern & st_term) (decreases b) =
let (p, e) = b in
let p = subst_pat p ss in
let ss = shift_subst_n (pattern_shift_n p) ss in
p, subst_st_term e ss
let open_st_term' (t:st_term) (v:term) (i:index) : st_term =
subst_st_term t [ DT i v ]
let open_term_nv t nv =
open_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_term t v : GTot term =
open_term_nv t (v_as_nv v)
let open_st_term_nv t nv =
open_st_term' t (U.term_of_nvar nv) 0
// Can use this no-name version in specs only
let open_st_term t v : GTot st_term =
open_st_term_nv t (v_as_nv v)
let open_comp_with (c:comp) (x:term) = open_comp' c x 0
let close_term' (t:term) (v:var) (i:index) : term =
subst_term t [ ND v i ]
let close_st_comp' (s:st_comp) (v:var) (i:index) : st_comp =
subst_st_comp s [ ND v i ]
let close_comp' (c:comp) (v:var) (i:index) : comp =
subst_comp c [ ND v i ]
let close_term_opt' (t:option term) (v:var) (i:index) : option term =
subst_term_opt t [ ND v i ]
let close_term_list' (t:list term) (v:var) (i:index) : list term =
subst_term_list t [ ND v i ]
let close_binder b v i =
subst_binder b [ ND v i ]
let close_st_term' (t:st_term) (v:var) (i:index) : st_term =
subst_st_term t [ ND v i ]
let close_term t v = close_term' t v 0
let close_st_term t v = close_st_term' t v 0
let close_comp t v = close_comp' t v 0 | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val close_term_n : t: Pulse.Syntax.Base.term -> vs: Prims.list Pulse.Syntax.Base.var -> Pulse.Syntax.Base.term | [] | Pulse.Syntax.Naming.close_term_n | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> vs: Prims.list Pulse.Syntax.Base.var -> Pulse.Syntax.Base.term | {
"end_col": 23,
"end_line": 668,
"start_col": 23,
"start_line": 661
} |
|
Prims.Tot | val freevars (t: term) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t | val freevars (t: term) : Set.set var
let rec freevars (t: term) : Set.set var = | false | null | false | match t.t with
| Tm_Emp | Tm_VProp | Tm_Inames | Tm_EmpInames | Tm_Unknown -> Set.empty
| Tm_Star t1 t2 -> Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2 | Tm_ForallSL _ t1 t2 -> Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"FStar.Set.empty",
"Pulse.Syntax.Base.var",
"FStar.Set.union",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Base.host_term",
"FStar.Reflection.Typing.freevars",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars (t: term) : Set.set var | [
"recursion"
] | Pulse.Syntax.Naming.freevars | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 33,
"end_line": 30,
"start_col": 4,
"start_line": 18
} |
Prims.Tot | val freevars_list (t: list term) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl | val freevars_list (t: list term) : Set.set var
let rec freevars_list (t: list term) : Set.set var = | false | null | false | match t with
| [] -> Set.empty
| hd :: tl -> (freevars hd) `Set.union` (freevars_list tl) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"FStar.Set.empty",
"Pulse.Syntax.Base.var",
"FStar.Set.union",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Naming.freevars_list",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_list (t: list term) : Set.set var | [
"recursion"
] | Pulse.Syntax.Naming.freevars_list | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list Pulse.Syntax.Base.term -> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 54,
"end_line": 57,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val freevars_opt (f: ('a -> Set.set var)) (x: option 'a) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x | val freevars_opt (f: ('a -> Set.set var)) (x: option 'a) : Set.set var
let freevars_opt (f: ('a -> Set.set var)) (x: option 'a) : Set.set var = | false | null | false | match x with
| None -> Set.empty
| Some x -> f x | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Set.set",
"Pulse.Syntax.Base.var",
"FStar.Pervasives.Native.option",
"FStar.Set.empty"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s | false | false | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_opt (f: ('a -> Set.set var)) (x: option 'a) : Set.set var | [] | Pulse.Syntax.Naming.freevars_opt | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | f: (_: 'a -> FStar.Set.set Pulse.Syntax.Base.var) -> x: FStar.Pervasives.Native.option 'a
-> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 17,
"end_line": 49,
"start_col": 2,
"start_line": 47
} |
Prims.Tot | val ln_terms' (t: list (term & term)) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i | val ln_terms' (t: list (term & term)) (i: int) : bool
let rec ln_terms' (t: list (term & term)) (i: int) : bool = | false | null | false | match t with
| [] -> true
| (t1, t2) :: tl -> ln' t1 i && ln' t2 i && ln_terms' tl i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Prims.int",
"Prims.op_AmpAmp",
"Pulse.Syntax.Naming.ln'",
"Pulse.Syntax.Naming.ln_terms'",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_terms' (t: list (term & term)) (i: int) : bool | [
"recursion"
] | Pulse.Syntax.Naming.ln_terms' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) -> i: Prims.int -> Prims.bool | {
"end_col": 58,
"end_line": 201,
"start_col": 2,
"start_line": 199
} |
Prims.Tot | val ln_opt' (t: option term) (i: int) : bool | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i | val ln_opt' (t: option term) (i: int) : bool
let ln_opt' (t: option term) (i: int) : bool = | false | null | false | match t with
| None -> true
| Some t -> ln' t i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Prims.int",
"Pulse.Syntax.Naming.ln'",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i | false | false | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln_opt' (t: option term) (i: int) : bool | [] | Pulse.Syntax.Naming.ln_opt' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> i: Prims.int -> Prims.bool | {
"end_col": 21,
"end_line": 191,
"start_col": 2,
"start_line": 189
} |
Prims.Tot | val ln' (t: term) (i: int) : Tot bool (decreases t) | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i | val ln' (t: term) (i: int) : Tot bool (decreases t)
let rec ln' (t: term) (i: int) : Tot bool (decreases t) = | false | null | false | match t.t with
| Tm_Emp | Tm_VProp | Tm_Inames | Tm_EmpInames | Tm_Unknown -> true
| Tm_Star t1 t2 -> ln' t1 i && ln' t2 i
| Tm_Pure p -> ln' p i
| Tm_ExistsSL _ t body | Tm_ForallSL _ t body -> ln' t.binder_ty i && ln' body (i + 1)
| Tm_FStar t -> RT.ln' t i | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total",
""
] | [
"Pulse.Syntax.Base.term",
"Prims.int",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Prims.op_AmpAmp",
"Pulse.Syntax.Naming.ln'",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Prims.op_Addition",
"Pulse.Syntax.Base.host_term",
"FStar.Reflection.Typing.ln'",
"Prims.bool"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ln' (t: term) (i: int) : Tot bool (decreases t) | [
"recursion"
] | Pulse.Syntax.Naming.ln' | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Pulse.Syntax.Base.term -> i: Prims.int -> Prims.Tot Prims.bool | {
"end_col": 14,
"end_line": 170,
"start_col": 2,
"start_line": 150
} |
Prims.Tot | val subst_term_opt (t: option term) (ss: subst) : Tot (option term) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss) | val subst_term_opt (t: option term) (ss: subst) : Tot (option term)
let subst_term_opt (t: option term) (ss: subst) : Tot (option term) = | false | null | false | match t with
| None -> None
| Some t -> Some (subst_term t ss) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.subst",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Naming.subst_term"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_term_opt (t: option term) (ss: subst) : Tot (option term) | [] | Pulse.Syntax.Naming.subst_term_opt | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> ss: Pulse.Syntax.Naming.subst
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.term | {
"end_col": 38,
"end_line": 441,
"start_col": 4,
"start_line": 439
} |
Prims.Tot | val freevars_comp (c: comp) : Tot (Set.set var) (decreases c) | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s | val freevars_comp (c: comp) : Tot (Set.set var) (decreases c)
let freevars_comp (c: comp) : Tot (Set.set var) (decreases c) = | false | null | false | match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s | C_STGhost inames s -> (freevars inames) `Set.union` (freevars_st_comp s) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total",
""
] | [
"Pulse.Syntax.Base.comp",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Naming.freevars_st_comp",
"FStar.Set.union",
"Pulse.Syntax.Base.var",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_comp (c: comp) : Tot (Set.set var) (decreases c) | [] | Pulse.Syntax.Naming.freevars_comp | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | c: Pulse.Syntax.Base.comp -> Prims.Tot (FStar.Set.set Pulse.Syntax.Base.var) | {
"end_col": 50,
"end_line": 44,
"start_col": 2,
"start_line": 39
} |
Prims.Tot | val subst_term_list (t: list term) (ss: subst) : Tot (list term) | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R2"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec subst_term_list (t:list term) (ss:subst)
: Tot (list term)
= match t with
| [] -> []
| hd::tl -> subst_term hd ss :: subst_term_list tl ss | val subst_term_list (t: list term) (ss: subst) : Tot (list term)
let rec subst_term_list (t: list term) (ss: subst) : Tot (list term) = | false | null | false | match t with
| [] -> []
| hd :: tl -> subst_term hd ss :: subst_term_list tl ss | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Naming.subst",
"Prims.Nil",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Naming.subst_term_list"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl
let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl
let freevars_proof_hint (ht:proof_hint_type) : Set.set var =
match ht with
| ASSERT { p }
| FOLD { p }
| UNFOLD { p } -> freevars p
| RENAME { pairs; goal } ->
Set.union (freevars_pairs pairs) (freevars_term_opt goal)
| REWRITE { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
let rec freevars_st (t:st_term)
: Set.set var
= match t.term with
| Tm_Return { term } ->
freevars term
| Tm_Abs { b; ascription; body } ->
Set.union (freevars b.binder_ty)
(Set.union (freevars_st body)
(freevars_comp ascription))
| Tm_STApp { head; arg } ->
Set.union (freevars head) (freevars arg)
| Tm_Bind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars_st head))
(freevars_st body)
| Tm_TotBind { binder; head; body } ->
Set.union
(Set.union (freevars binder.binder_ty)
(freevars head))
(freevars_st body)
| Tm_If { b; then_; else_; post } ->
Set.union (Set.union (freevars b) (freevars_st then_))
(Set.union (freevars_st else_) (freevars_term_opt post))
| Tm_Match { sc ; returns_; brs } ->
let (@@) = Set.union in
freevars sc
@@ freevars_term_opt returns_
@@ freevars_branches brs
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
freevars p
| Tm_IntroExists { p; witnesses } ->
Set.union (freevars p) (freevars_list witnesses)
| Tm_While { invariant; condition; body } ->
Set.union (freevars invariant)
(Set.union (freevars_st condition)
(freevars_st body))
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
Set.union
(Set.union (freevars pre1)
(Set.union (freevars_st body1)
(freevars post1)))
(Set.union (freevars pre2)
(Set.union (freevars_st body2)
(freevars post2)))
| Tm_WithLocal { binder; initializer; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(freevars_st body))
| Tm_WithLocalArray { binder; initializer; length; body } ->
Set.union (freevars binder.binder_ty)
(Set.union (freevars initializer)
(Set.union (freevars length)
(freevars_st body)))
| Tm_Rewrite { t1; t2 } ->
Set.union (freevars t1) (freevars t2)
| Tm_Admit { typ; post } ->
Set.union (freevars typ)
(freevars_term_opt post)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
Set.union (freevars_proof_hint hint_type) (freevars_st t)
and freevars_branches (t:list (pattern & st_term)) : Set.set var =
match t with
| [] -> Set.empty
| (_, b)::tl -> freevars_st b `Set.union` freevars_branches tl
let rec ln' (t:term) (i:int) : Tot bool (decreases t) =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> true
| Tm_Star t1 t2 ->
ln' t1 i &&
ln' t2 i
| Tm_Pure p ->
ln' p i
| Tm_ExistsSL _ t body
| Tm_ForallSL _ t body ->
ln' t.binder_ty i &&
ln' body (i + 1)
| Tm_FStar t ->
RT.ln' t i
let ln_st_comp (s:st_comp) (i:int) : bool =
ln' s.res i &&
ln' s.pre i &&
ln' s.post (i + 1) (* post has 1 impliict abstraction *)
let ln_c' (c:comp) (i:int)
: bool
= match c with
| C_Tot t -> ln' t i
| C_ST s -> ln_st_comp s i
| C_STAtomic inames s
| C_STGhost inames s ->
ln' inames i &&
ln_st_comp s i
let ln_opt' (t:option term) (i:int) : bool =
match t with
| None -> true
| Some t -> ln' t i
let rec ln_list' (t:list term) (i:int) : bool =
match t with
| [] -> true
| hd::tl -> ln' hd i && ln_list' tl i
let rec ln_terms' (t:list (term & term)) (i:int) : bool =
match t with
| [] -> true
| (t1, t2)::tl -> ln' t1 i && ln' t2 i && ln_terms' tl i
let ln_proof_hint' (ht:proof_hint_type) (i:int) : bool =
match ht with
| ASSERT { p }
| UNFOLD { p }
| FOLD { p } -> ln' p i
| RENAME { pairs; goal } ->
ln_terms' pairs i &&
ln_opt' goal i
| REWRITE { t1; t2 } ->
ln' t1 i &&
ln' t2 i
let rec pattern_shift_n (p:pattern)
: Tot nat
= match p with
| Pat_Constant _
| Pat_Dot_Term _ ->
0
| Pat_Var _ _ ->
1
| Pat_Cons fv l ->
pattern_args_shift_n l
and pattern_args_shift_n (ps:list (pattern & bool))
: Tot nat
= match ps with
| [] -> 0
| (p, _)::tl ->
pattern_shift_n p + pattern_args_shift_n tl
let rec ln_pattern' (p : pattern) (i:int)
: Tot bool (decreases p)
= match p with
| Pat_Constant _
| Pat_Var _ _
| Pat_Dot_Term None ->
true
| Pat_Dot_Term (Some e) ->
ln' e i
| Pat_Cons fv l ->
ln_pattern_args' l i
and ln_pattern_args' (p:list (pattern & bool)) (i:int)
: Tot bool (decreases p)
= match p with
| [] ->
true
| (p, _)::tl ->
ln_pattern' p i &&
ln_pattern_args' tl (i + pattern_shift_n p)
let rec ln_st' (t:st_term) (i:int)
: Tot bool (decreases t)
= match t.term with
| Tm_Return { term } ->
ln' term i
| Tm_Abs { b; ascription; body } ->
ln' b.binder_ty i &&
ln_st' body (i + 1) &&
ln_c' ascription (i + 1)
| Tm_STApp { head; arg } ->
ln' head i &&
ln' arg i
| Tm_Bind { binder; head; body } ->
ln' binder.binder_ty i &&
ln_st' head i &&
ln_st' body (i + 1)
| Tm_TotBind { binder; head; body } ->
ln' binder.binder_ty i &&
ln' head i &&
ln_st' body (i + 1)
| Tm_If { b; then_; else_; post } ->
ln' b i &&
ln_st' then_ i &&
ln_st' else_ i &&
ln_opt' post (i + 1)
| Tm_Match {sc; returns_; brs } ->
ln' sc i &&
ln_opt' returns_ i &&
ln_branches' t brs i
| Tm_IntroPure { p }
| Tm_ElimExists { p } ->
ln' p i
| Tm_IntroExists { p; witnesses } ->
ln' p i &&
ln_list' witnesses i
| Tm_While { invariant; condition; body } ->
ln' invariant (i + 1) &&
ln_st' condition i &&
ln_st' body i
| Tm_Par { pre1; body1; post1; pre2; body2; post2 } ->
ln' pre1 i &&
ln_st' body1 i &&
ln' post1 (i + 1) &&
ln' pre2 i &&
ln_st' body2 i &&
ln' post2 (i + 1)
| Tm_WithLocal { binder; initializer; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln_st' body (i + 1)
| Tm_WithLocalArray { binder; initializer; length; body } ->
ln' binder.binder_ty i &&
ln' initializer i &&
ln' length i &&
ln_st' body (i + 1)
| Tm_Rewrite { t1; t2 } ->
ln' t1 i &&
ln' t2 i
| Tm_Admit { typ; post } ->
ln' typ i &&
ln_opt' post (i + 1)
| Tm_ProofHintWithBinders { binders; hint_type; t } ->
let n = L.length binders in
ln_proof_hint' hint_type (i + n) &&
ln_st' t (i + n)
and ln_branch' (b : pattern & st_term) (i:int) : Tot bool (decreases b) =
let (p, e) = b in
ln_pattern' p i &&
ln_st' e (i + pattern_shift_n p)
and ln_branches' (t:st_term) (brs : list branch{brs << t}) (i:int) : Tot bool (decreases brs) =
for_all_dec t brs (fun b -> ln_branch' b i)
let ln (t:term) = ln' t (-1)
let ln_st (t:st_term) = ln_st' t (-1)
let ln_c (c:comp) = ln_c' c (-1)
noeq
type subst_elt =
| DT : nat -> term -> subst_elt
| NT : var -> term -> subst_elt
| ND : var -> nat -> subst_elt
let shift_subst_elt (n:nat) = function
| DT i t -> DT (i + n) t
| NT x t -> NT x t
| ND x i -> ND x (i + n)
let subst = list subst_elt
let shift_subst_n (n:nat) = L.map (shift_subst_elt n)
let shift_subst = shift_subst_n 1
let rt_subst_elt = function
| DT i t -> RT.DT i (E.elab_term t)
| NT x t -> RT.NT x (E.elab_term t)
| ND x i -> RT.ND x i
let rt_subst = L.map rt_subst_elt
let open_or_close_host_term (t:host_term) (ss:subst)
: Lemma (not_tv_unknown (RT.subst_term t (rt_subst ss)))
= admit()
val subst_host_term (t:host_term) (ss:subst)
: Tot (t':host_term { t' == RT.subst_term t (rt_subst ss) })
let rec subst_term (t:term) (ss:subst)
: Tot term (decreases t)
= let w t' = with_range t' t.range in
match t.t with
| Tm_VProp
| Tm_Emp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> t
| Tm_Pure p ->
w (Tm_Pure (subst_term p ss))
| Tm_Star l r ->
w (Tm_Star (subst_term l ss)
(subst_term r ss))
| Tm_ExistsSL u b body ->
w (Tm_ExistsSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_ForallSL u b body ->
w (Tm_ForallSL u { b with binder_ty = subst_term b.binder_ty ss }
(subst_term body (shift_subst ss)))
| Tm_FStar t ->
w (Tm_FStar (subst_host_term t ss))
let open_term' (t:term) (v:term) (i:index) =
subst_term t [ DT i v ]
let subst_st_comp (s:st_comp) (ss:subst)
: st_comp =
{ s with res = subst_term s.res ss;
pre = subst_term s.pre ss;
post = subst_term s.post (shift_subst ss) }
let open_st_comp' (s:st_comp) (v:term) (i:index) : st_comp =
subst_st_comp s [ DT i v ]
let subst_comp (c:comp) (ss:subst)
: comp
= match c with
| C_Tot t ->
C_Tot (subst_term t ss)
| C_ST s -> C_ST (subst_st_comp s ss)
| C_STAtomic inames s ->
C_STAtomic (subst_term inames ss)
(subst_st_comp s ss)
| C_STGhost inames s ->
C_STGhost (subst_term inames ss)
(subst_st_comp s ss)
let open_comp' (c:comp) (v:term) (i:index) : comp =
subst_comp c [ DT i v ]
let subst_term_opt (t:option term) (ss:subst)
: Tot (option term)
= match t with
| None -> None
| Some t -> Some (subst_term t ss)
let open_term_opt' (t:option term) (v:term) (i:index)
: Tot (option term) = subst_term_opt t [ DT i v ]
let rec subst_term_list (t:list term) (ss:subst) | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val subst_term_list (t: list term) (ss: subst) : Tot (list term) | [
"recursion"
] | Pulse.Syntax.Naming.subst_term_list | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | t: Prims.list Pulse.Syntax.Base.term -> ss: Pulse.Syntax.Naming.subst
-> Prims.list Pulse.Syntax.Base.term | {
"end_col": 57,
"end_line": 450,
"start_col": 4,
"start_line": 448
} |
Prims.Tot | val freevars_pairs (pairs: list (term & term)) : Set.set var | [
{
"abbrev": true,
"full_module": "Pulse.Elaborate.Pure",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Pure",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "FStar.Reflection",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec freevars_pairs (pairs:list (term & term)) : Set.set var =
match pairs with
| [] -> Set.empty
| (t1, t2)::tl -> Set.union (freevars t1) (freevars t2) `Set.union` freevars_pairs tl | val freevars_pairs (pairs: list (term & term)) : Set.set var
let rec freevars_pairs (pairs: list (term & term)) : Set.set var = | false | null | false | match pairs with
| [] -> Set.empty
| (t1, t2) :: tl -> (Set.union (freevars t1) (freevars t2)) `Set.union` (freevars_pairs tl) | {
"checked_file": "Pulse.Syntax.Naming.fsti.checked",
"dependencies": [
"Pulse.Syntax.Pure.fst.checked",
"Pulse.Syntax.Base.fsti.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Common.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.Typing.Builtins.fsti.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Reflection.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Pulse.Syntax.Naming.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"FStar.Set.empty",
"Pulse.Syntax.Base.var",
"FStar.Set.union",
"Pulse.Syntax.Naming.freevars",
"Pulse.Syntax.Naming.freevars_pairs",
"FStar.Set.set"
] | [] | module Pulse.Syntax.Naming
open FStar.List.Tot
open Pulse.Syntax.Base
open Pulse.Common
module L = FStar.List.Tot
module R = FStar.Reflection
module RTB = FStar.Reflection.Typing.Builtins
module RT = FStar.Reflection.Typing
module RU = Pulse.RuntimeUtils
module U = Pulse.Syntax.Pure
module E = Pulse.Elaborate.Pure
let rec freevars (t:term)
: Set.set var
= match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Unknown -> Set.empty
| Tm_Star t1 t2 ->
Set.union (freevars t1) (freevars t2)
| Tm_ExistsSL _ t1 t2
| Tm_ForallSL _ t1 t2 ->
Set.union (freevars t1.binder_ty) (freevars t2)
| Tm_Pure p -> freevars p
| Tm_FStar t -> RT.freevars t
let freevars_st_comp (s:st_comp) : Set.set var =
freevars s.res `Set.union`
freevars s.pre `Set.union`
freevars s.post
let freevars_comp (c:comp) : Tot (Set.set var) (decreases c) =
match c with
| C_Tot t -> freevars t
| C_ST s -> freevars_st_comp s
| C_STAtomic inames s
| C_STGhost inames s ->
freevars inames `Set.union` freevars_st_comp s
let freevars_opt (f: 'a -> Set.set var) (x:option 'a) : Set.set var =
match x with
| None -> Set.empty
| Some x -> f x
let freevars_term_opt (t:option term) : Set.set var =
freevars_opt freevars t
let rec freevars_list (t:list term) : Set.set var =
match t with
| [] -> Set.empty
| hd::tl -> freevars hd `Set.union` freevars_list tl | false | true | Pulse.Syntax.Naming.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val freevars_pairs (pairs: list (term & term)) : Set.set var | [
"recursion"
] | Pulse.Syntax.Naming.freevars_pairs | {
"file_name": "lib/steel/pulse/Pulse.Syntax.Naming.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | pairs: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term)
-> FStar.Set.set Pulse.Syntax.Base.var | {
"end_col": 87,
"end_line": 62,
"start_col": 2,
"start_line": 60
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.